I am having a sample shell script file. In my script file I have a json data in a variable and also i have a file containing json .I want to compare the contents of the file against the variable using jq.
The following is my script file
RESPONSE='{remoteIds:[{remoteId:[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8080),requestsReceived:1},{remoteId:[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8081),requestsReceived:1},{remoteId:[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8082),requestsReceived:1},{remoteId:[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8083),requestsReceived:1}]}' expected_response='/test/scripts/tests/local-policy/expectedTestResponse1.json' echo $RESPONSE echo $expected_response # Compare JSON objects using jq if jq --argjson var "$RESPONSE" -e '. == $var'"$expected_response" > /dev/null 2>&1; then echo 0 # JSON objects are equal else echo 1 # JSON objects are unequal exit 1 fi
The content of the file expectedTestResponse1.json is below
{"remoteIds": [ {"remoteId": "[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8080)","requestsReceived": 1 }, {"remoteId": "[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8081)","requestsReceived": 1 }, {"remoteId": "[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8082)","requestsReceived": 1 }, {"remoteId": "[fd00:10:244:3:0:0:0:14]--(http://fd00-10-244-3--14.scctest.pod:8083)","requestsReceived": 1 } ]}
when i execute the script my script fails and exits . any idea what is happening. I would expect to print echo 0
thank you