Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 610

comparing json data failing when using jq? [closed]

$
0
0

I have a shell script. In the script, i am comparing json in a variable against another json in a file . The following is my sample code snippet.

RESPONSE=$(curl --connect-timeout 1 -s -f -X POST  -H "Content-Type: application/json" -d  "@${REQUEST}" $TEST_URL_HTTP)expected_response_file=${EXPECTED_RESPONSE_TEST_1}    # Compare http response JSON objects with generated test response json using jq    if jq --argjson var "$RESPONSE" -e '. == $var'"$expected_response_file" > /dev/null 2>&1; then      echo 0      echo "Test passed"    else      echo 1  # JSON objects are unequal      echo "Test failed"      exit 1    fi

However the comparison logic fails occasionally . for one such failure following is the test data

RESPONSE{"remoteIds":[{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8080)","requestsReceived":2},{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8081)","requestsReceived":2},{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8082)","requestsReceived":2},{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8083)","requestsReceived":2},{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8080)","requestsReceived":2},{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8081)","requestsReceived":2},{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8082)","requestsReceived":2},{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8083)","requestsReceived":2}]}expected_response_file{"remoteIds":[{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8080)","requestsReceived":2},{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8081)","requestsReceived":2},{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8082)","requestsReceived":2},{"remoteId":"[fd00:10:244:2:0:0:0:7]--(http://fd00-10-244-2--7.scctest.pod:8083)","requestsReceived":2},{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8080)","requestsReceived":2},{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8081)","requestsReceived":2},{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8082)","requestsReceived":2},{"remoteId":"[fd00:10:244:1:0:0:0:6]--(http://[fd00:10:244:1:0:0:0:6]:8083)","requestsReceived":2}]}

appreciate any helpthank you


Viewing all articles
Browse latest Browse all 610

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>