Is there a way to merge two JSON files on a key but preserve empty keys, preferably in JQ?
The files are merged on url.
File 1:
[
{
"url": "ABC",
"name": "Search",
"version": "2020",
"Ocurrences": "25"
},
{
"url": "DEF",
"name": "Welcome",
"version": "2021",
"Ocurrences": "10"
}
]
File 2:
[
{
"url": "DEF",
"title": "Support"
},
{
"url": "GHI",
"title": "Contact"
}
]
Desired result:
[
{
"url": "ABC",
"title": "",
"name": "Search",
"version": "2020",
"Ocurrences": "25"
},
{
"url": "DEF",
"title": "Support",
"name": "Welcome",
"version": "2021",
"Ocurrences": "10"
},
{
"url": "GHI",
"title": "Contact",
"name": "",
"version": "",
"Ocurrences": ""
}
]
Current JQ script:
jq -M '[group_by(.url)[]|add]' fi1e1.json file2.json > output.json
Current result:
[
{
"url": "ABC",
"name": "Search",
"version": "2020",
"Ocurrences": "25"
},
{
"url": "DEF",
"title": "Support",
"name": "Welcome",
"version": "2021",
"Ocurrences": "10"
},
{
"url": "GHI",
"title": "Contact"
}
]
The real files have 100+ objects. Order of keys doesn't matter. JQ is preferred because I know Bash only.
The goal is to merge data extracted from Azure Application Insights with data on a local hard drive.
Thank you for any help or direction.