I am using jq tools to merge 2 json files but there are some duplicate keys, and I would like for the duplicate keys to sum their values.
Here are the files:
file1:
{
"total": {
"seconds": 1490
},
"days": {
"2020-05-20": {
"seconds": 1400
},
"2020-05-19": {
"seconds": 30
},
"2020-05-18": {
"seconds": 60
}
}
}
file2:
{
"total": {
"seconds": 295
},
"days": {
"2020-05-22": {
"seconds": 120
},
"2020-05-21": {
"seconds": 80
},
"2020-05-20": {
"seconds": 95
}
}
}
Expected output:
{
"total": {
"seconds": 1785
},
"days": {
"2020-05-22": {
"seconds": 120
},
"2020-05-21": {
"seconds": 80
},
"2020-05-20": {
"seconds": 1495
},
"2020-05-19": {
"seconds": 30
},
"2020-05-18": {
"seconds": 60
}
}
}
I have tried starting with this command, but do not know where to go next:
jq -s '.[0] * .[1]' file1 file2