Given this
{
"some": "property",
"nested": {
"hello": "world"
}
}
I'd like to get this result with jq
{
"some": "property",
"nested": {
"hello": "world",
"freshly": "added"
}
}
So how can I add the freshly added field ? I don't know how many properties are at root level (and I want to keep them all), I only know the name of the nested object (here "nested"), the name of the property I'd like to add (here "freshly") and its value.
Just assign the new value to the nested object.
.nested.freshly = "added"
Well I found out myself how to do it. If you have a better solution, you're more than welcome to give it here.
jq '.nested=(.nested + {"freshly": "added"})'
You can also do simply
.nested += {freshly: "added"}
Then you can add multiple nested keys at once
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