I have 2 json objects in 2 variables V1 and V2.
V1 is
{
"Parameters: {
"a": "value-of-a",
"b": "value-of-b"
}
}
V2 is
{
"Parameters": {
"a": "new-value-of-a",
"c": "value-of-c"
}
}
I want to override the V1's values with values from V2. I want to generate a new JSON that looks like this:
Expected
{
"Parameters": {
"a": "new-value-of-a",
"b": "value-of-b"
}
}
I tried the following:
(
echo '{ "Parameters": { "a": "value-of-a", "b": "value-of-b" } }'\
'{ "Parameters": { "a": "new-value-of-a", "c": "value-of-c" } }'\
| jq --slurp 'reduce .[] as $item ({}; . * $item)'
)
but this generates
Actual
{
"Parameters": {
"a": "new-value-of-a",
"b": "value-of-b",
"c": "value-of-c"
}
}
The problem is that I don't want the nodes in V2 that don't exist in V1 to appear in the result. Can anyone help me?