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 ((
2
Answers
Instead of
keys
I would start withto_entries
:(online demo)
The reverse then is
(online demo)