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

using a pipe symbol in a jq command throws an error

$
0
0

I am having a shell script file validation-example.sh , it has the followign content

expected_template = '{"remoteIds": [    {"remoteId": "","requestsReceived": 1    },    {"remoteId": "","requestsReceived": 1    },    {"remoteId": "","requestsReceived": 1    },    {"remoteId": "","requestsReceived": 1    }  ]}'actual_json = '{"remoteIds": [    {"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8080)","requestsReceived": 1    },    {"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8081)","requestsReceived": 1    },    {"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8082)","requestsReceived": 1    },    {"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8083)","requestsReceived": 1    }  ]}'validate_json() {    local data="$1"    local template="$2"    jq -e "$data | $template" >/dev/null}if validate_json "$actual_json" "$expected_template"; then    echo "The actual JSON matches the expected template."else    echo "The actual JSON does not match the expected template."fi

However when i run the file it is returning the following error

validation-example.sh: line 1: expected_template: command not foundvalidation-example.sh: line 22: actual_json: command not foundjq: error: syntax error, unexpected '|', expecting $end (Unix shell quoting issues?) at <top-level>, line 1: |  jq: 1 compile errorThe actual JSON does not match the expected template.

any help pleasethanks


Viewing all articles
Browse latest Browse all 608

Trending Articles



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