I have two JSON input files that I want to merge recursively:
file1.json
{
"key1": {
"key1.1": "foo",
"key1.2": "bar"
},
"key2": {
"key2.1": "daz"
}
}
file2.json
{
"key1": {
"key1.3": "dingo"
},
"key2": {
"key2.2": "lorem"
}
}
I know I can combine these two with --slurp and the * operator:
jq --slurp '.[0] * .[1]' file1.json file2.json
{
"key1": {
"key1.1": "foo",
"key1.2": "bar",
"key1.3": "dingo"
},
"key2": {
"key2.1": "daz",
"key2.2": "lorem"
}
}
And of course I can do this with any number of files, as long as I know the exact number of input files. However, how can the '.[0] * .[1]' part be generalised to work with an arbitrary number of input files?
For the + operator I could do '. | add', but + isn't what I want. Is there an equivalent to add for *?