I have a json file that has the following structures
{
"a":"aval",
"b":{},
"c":"cval"
}
I have another json file with following content
{
"b1":"b1val","b2":"b2val"
}
I want to shove the json object from file 2 into "b" from file 1
{
"a":"aval",
"b":{
"b1":"b1val","b2":"b2val"
},
"c":"cval"
}
how do i do this with JQ
Assuming file #2 may not be empty, you can simply assign input to .b.
jq '.b = input' file1 file2
Online demo
Otherwise you'd use the following to retain the original value of .b when file #2 is empty.
jq '.b = first(inputs, .b)' file1 file2
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