I have the following json files:
common.json
{"common": {"Hello": "ABC" },"east": {"Direction": "East" },"west": {"Direction": "West" }}
pi.json
{"common": {"MyUri": "www.myuri.com" },"east": {"App-Env": "my-pi","SentinelValue": 1713311902 },"west": {"App-Env": "my-piw","SentinelValue": 1713311902 }}
basically I want to create a new json file where everything from "east" key of common.json +"common" key of common.json + the "common" key of pi.json + the "east" key of pi.json are moved to one json file.
I have the following script that is not working the way I thought it would:
jq_input_files=("common.json" "pi.json") jq --slurp 'map({ ((.common | keys_unsorted[])): .common[], ((.east | keys_unsorted[])): .east[] }) | add'"${jq_input_files[@]}" > "test.json"
The content of test.json from this script is:
{"MyUri": "www.myuri.com","App-Env": my-pi,"SentinelValue": 1713311902}
The output I wanted for test.json is:
{"MyUri": "www.myuri.com","App-Env": 1713311902,"SentinelValue": 1713311902,"Hello": "ABC","Direction": "East"}
The two main issues I cant figure out:
- It seems that nothing is being pulled from my common.json file even though both files are passed in.
- It seems that App-Env is now being updated with the same value as my sentinelValue which I do not want to happen.