How can I output the objects from a JSON file which doesn't match in another JSON file. For Example,
file1:
[
{
"name": "ABC",
"age": "23",
"address": "xyz"
},
{
"name": "DEF",
"age": "24",
"address": "pqr"
}
]
file2:
[
{
"name": "ABC",
"age": "23",
"address": "xyz"
},
{
"name": "GHI",
"age": "24",
"address": "pqr"
}
]
I want the output from file2 which doesn't match in file1. Example:
output file:
[
{
"name": "GHI",
"age": "24",
"address": "pqr"
}
]
I am looking to do it in shell script using Jq.
CodePudding user response:
The jq minus operator does exactly what you need. Just use --slurpfile
to get both files into variables:
jq -n --slurpfile file1 file1.json --slurpfile file2 file2.json '$file2[0] - $file1[0]'