Using jq, is it possible to update property value of an object that contains a specific value in some other property?
In the example below I'd like to set the value of the "value" property of all objects that have "keyname" = "foo".
The example .json file looks like this:
"root" : {
"instances": [
{
"name": "1",
"configs": [
{
"keyname": "foo",
"value": "" // <- update/set this
},
{
"keyname": "barrr",
"value": "barrrr"
}
]
},
{
"name": "2",
"configs": [
{
"keyname": "foo",
"value": "" // <- update/set this
},
{
"keyname": "buzzz",
"value": "buzzz"
}
]
}
]
}
I tried this but in vain, I get an error about array not being a string:
jq '(.root.instances.configs[] | select(.keyname==foo)).value = foo'