Issue
I have JSON data I got by using lscpu
Linux command with the -J
flag.
It outputs array with elements with such format:
{"field":"fieldName", "data":"information"}
How can I change its format to
{"fieldName":"information"}
using lscpu
either jq
?
I tried to make it via script, but I think there'd be prettier way.
Example
A more detailed example output from lscpu --json
{
"lscpu": [
{"field": "Architecture:", "data": "x86_64"},
{"field": "CPU op-mode(s):", "data": "32-bit, 64-bit"},
{"field": "Byte Order:", "data": "Little Endian"},
... omitted lines
{"field": "Flags:", "data": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid aperfmperf pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid fsrm arch_capabilities"}
]
}
Solution
The method I've searched for is used in lscpu
Linux command, so the final version would be
lscpu -J | jq '.lscpu | map( { (.field): .data } ) | add'
resulting into the required output of, in example
{
"Architecture:": "x86_64",
"CPU op-mode(s):": "32-bit, 64-bit",
"Byte Order:": "Little Endian",
... omitted lines
"Flags:": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid aperfmperf pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid fsrm arch_capabilities"
}
Answered By - Aleksey Answer Checked By - Cary Denson (WPSolving Admin)