I have a json like this:
{
"key_1": {
"type": "string",
"value": "foo"
},
"key_2": {
"type": "string",
"value": "bar"
}
}
that I would like to output like this
{
"key_1": "foo",
"key_2": "bar"
}
jq '.[].value' will give me the values:
"foo"
"bar"
while this jq '(.[] = .[].value)' will give me
{
"key_1": "foo",
"key_2": "foo"
}
{
"key_1": "bar",
"key_2": "bar"
}
So I'm not sure..
Since the task entails mapping the values of the top-level keys, map_values should come to mind:
map_values(.value)
You could also use with_entries, which might make sense if you wanted to manipulate the top-level keys as well:
with_entries( .value |= .value )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With