Skip to main content
7 of 10
added 1 character in body
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k

Maybe:

$ jq -c 'map(.[]|map(.key=.field)|from_entries|del(."@ptr"))' file.json | mlr --ijson --opprint --barred cat +-------------------------+-------------+-------------------+----------------+----------------+ | @timestamp | CpuReserved | CpuUtilized | MemoryReserved | MemoryUtilized | +-------------------------+-------------+-------------------+----------------+----------------+ | 2023-07-03 08:28:00.000 | 8192.0 | 4056.412942708333 | 61440 | 4311 | | 2023-07-03 08:28:00.000 | 8192.0 | 4056.412942708333 | 61440 | 4311 | +-------------------------+-------------+-------------------+----------------+----------------+ 

Without --barred, that looks like:

 @̱ṯi̱m̱e̱s̱ṯa̱m̱p̱ C̱p̱u̱Ṟe̱s̱e̱ṟv̱e̱ḏ C̱p̱u̱U̱ṯi̱ḻi̱ẕe̱ḏ M̱e̱m̱o̱ṟy̱Ṟe̱s̱e̱ṟv̱e̱ḏ M̱e̱m̱o̱ṟy̱U̱ṯi̱ḻi̱ẕe̱ḏ 2023-07-03 08:28:00.000 8192.0 4056.412942708333 61440 4311 2023-07-03 08:28:00.000 8192.0 4056.412942708333 61440 4311 

You could also pipe the output of that jq command to vd -f json (visidata) instead of mlr to get an interactive table viewer.

Those use jq to extract the information and mlr only to format the table. There is some overlap between the feature set of jq and that of mlr. For instance, you could also remove the @ptr column with mlr's cut:

jq -c 'map(.[]|map(.key=.field)|from_entries)' file.json | mlr --ijson --opprint cut -xf @ptr 
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k