I need to change the value of a set of keys (defined in a variable) in a JSON object using jq.
As example, I have this JSON object:
{
foo: {
bar: 1,
baz: 2,
qux: 3
}
}
and the following variable:
update_keys = ["bar", "baz"]
I would like to say 'change the value of the keys in update_keys to X'.
The following works:
.foo = (.foo |
to_entries |
map(if .key == "bar" or .key == "baz"
then . + { "value":"X" }
else .
end) |
from_entries)
But instead of if .key == "bar" or .key == "baz" I am looking for a way to say if .key in update_keys, or a similar logic.
update_keysalready a variable that you've defined injq?