Quantcast
Viewing all articles
Browse latest Browse all 519

JSON: moving item's key/name into attribute and convert it to array with jq

here is original json example:

{"item1": {"foo1": 1,"foo2": 2},"item2": {"foo1": 11,"foo2": 22  }}

how can i convert it into json array with new attribute using jq:

[  {"name": "item1","foo1": 1,"foo2": 2  },  {"name": "item2","foo1": 11,"foo2": 22  }]

also, it's very interesting, how opposite conversion can be done as well!

thanks in advance!

i have been trying different approaches using "keys" and "keys_unsorted", but never got it work ((


Viewing all articles
Browse latest Browse all 519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>