Merge values from a JSON file into a new key-value in another JSON file
Let's say I have two files.
ip.json
{
"host1": "1.1.1.1",
"host2": "1.1.1.2",
"host3": "1.1.1.3"
}
specs.json
{
"host1": {
"cores": 2,
"memory": 4
},
"host2": {
"cores": 4,
"memory": 8
},
"host3": {
"cores": 2,
"memory": 6
}
}
I want to merge the information from ip.json into a new field in specs.json, so the result would be like this:
result.json
{
"host1": {
"cores": 2,
"memory": 4,
"address": "1.1.1.1"
},
"host2": {
"cores": 4,
"memory": 8,
"address": "1.1.1.2"
},
"host3": {
"cores": 2,
"memory": 6,
"address": "1.1.1.2"
}
}
Is there a way doing what I want using jq ?