I'm trying to combine two json files with arrays in common using jq (example below):
file1.json
{
"veg": {
"trolley": [
"potato"
],
"total_items": [
1
]
}
}
file2.json
{
"veg": {
"trolley": [
"lettuce",
"tomato"
],
"total_items": [
2
]
}
}
Desired output:
{
"veg": {
"trolley": [
"potato",
"lettuce",
"tomato"
],
"total_items": [
1,
2
]
}
}
I appreciate the json seems a bit of a poor example, I'm just trying to add in some numbers (my data contains numbers and strings).
If I do jq -s 'add', the results get overwritten; map and flatten yield similar results, if I use "|= . +" I end up with the same value in all the arrays.
Any help would be much appreciated and my apologies in advance if this has been resolved previously (I promise I looked!).