I've used jq for a few parsing tasks, just got started with it a couple of days ago and am enjoying its versatility, but the one task I've outlined below is a bit more complicated and I'm stuck wresting with jq over this one.
I have 2 files, both with similar schema for data. Files A and B, and what I'm hoping to get as output, looks like the following:
File A:
[
{
"type": "hive-site",
"tag": 1507894175,
"properties" : {
"javax.jdo.option.ConnectionPassword" : "hortonworks1"
}
},
{
"type": "admin-properties",
"tag": 1507894175,
"properties": {
"fieldA": "valueA",
"fieldB": "valueB"
}
}
]
File B:
[
{
"type": "hive-site",
"properties" : {
"javax.jdo.option.ConnectionPassword" : "hortonworks2"
}
},
{
"type": "admin-properties",
"properties": {
"fieldA": "valueA",
"fieldB": "valueB",
"fieldC": "valueC"
}
},
{
"type": "other-type",
"properties": {
"newFieldA": "valueA",
"newFieldB": "valueB"
}
}
]
Result: File C (File A as base, with modifications from File B)
[
{
"type": "hive-site",
"tag": 1507894175,
"properties" : {
"javax.jdo.option.ConnectionPassword" : "hortonworks2"
}
},
{
"type": "admin-properties",
"tag": 1507894175,
"properties": {
"fieldA": "valueA",
"fieldB": "valueB",
"fieldC": "valueC"
}
},
{
"type": "other-type",
"tag": NEW,
"properties": {
"newFieldA": "valueA",
"newFieldB": "valueB"
}
}
]
I'd like to take all of the pairs under "properties" from File B and push those to File A, updating existing property pairs if they exist, or adding them as their own block (with a "NEW" tag as shown) if they do not.
I've found similar answers (here and here), but none are close enough to be able to modify for my purposes.
Thank you!!