I have a json like this
{
"outer1": {
"outer2": {
"outer3": {
"key1": "value1",
"key2": "value2"
}
},
"outer4": {
"key1": "value1",
"key2": "value2"
}
}
}
I want output to be
[outer1.outer2.outer3]
key1 = value1
key2 = value2
[outer1.outer2.outer4]
key1 = value1
key2 = value2
I tried jq -r 'to_entries|map("(.key)=(.value|tostring)")|.[]' test.json
But its not what is what I want exactly
2
Answers
Assuming your input looks like this:
You could use the
--stream
option to read the input as a stream of path-value pairs. For instance:Next, format this JSON according to your needs. For example using
to_entries
for both levels:My take is this:
Basically:
["outer1","outer2","outer3","key1"]
)outer1.outer2.outer3
), a key (key1
) and the actual value (value1
)