简体   繁体   中英

nested objects with arbitrary keys to key-value objects with jq

There is an json object with n nested objects, where the key ist arbitrary and the nested objects have all the same structure.

Example:

{
  "albert":{ 
       "age": 35
  }, 
  "sarah":{ 
       "age": 33
  },
  "otto":{
        "age":27
  }
}

with jq the output should be an array and look like this:

[
  {"name":"albert","age":35},
  {"name":"sarah"","age":32},
  {"name":"otto","age":27},
]

Can somebody help me?

Thank you,

to_entries
| map( {name: .key, age: .value.age} )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM