I have a json object stored in a shell variable json
:
{
"name": "foo",
"array": [
{
"name": "bar",
"thing": true
},
{
"name": "baz",
"thing": false
}
]
}
I would like to add a new key (lets call it new_key
) to both objects within array
. I can do the following:
$ jq '.array[] + {"new_key": 0}' <<<"$json"
{
"name": "bar",
"thing": true,
"new_key": 0
}
{
"name": "baz",
"thing": false,
"new_key": 0
}
However that only returns the array array and not the entire object. How could I either modify the variable in place or return the entire object?