'jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at <top-level>
cat explorer/connection-profile/test-network.json | jq ".organizations.Org1MSP.adminPrivateKey.path |= 44ab"
jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
.organizations.Org1MSP.adminPrivateKey.path|=44ab
jq: 1 compile error
but it works fine with
cat explorer/connection-profile/test-network.json | jq ".organizations.Org1MSP.adminPrivateKey.path |= 44"
Why?
Actually I am trying to use
cat explorer/connection-profile/test-network.json | jq ".organizations.Org1MSP.adminPrivateKey.path |= ${PRIV_KEY}"
where the ${PRIV_KEY} is 44ab..._sk
Solution 1:[1]
You can assign a string to a variable that can be used inside a jq
filter:
PRIV_KEY="44ab..._sk"
jq --arg path "$PRIV_KEY" '.organizations.Org1MSP.adminPrivateKey.path |= $path' explorer/connection-profile/test-network.json
This method is safer than trying to embed an expanded shell variable directly in the filter string because jq
will properly handle arbitrary values instead of choking on things like quotes (Or their absence).
Note that jq
takes filenames as arguments after the filter expression; no need for cat
here (Unless that's standing in for curl
or something, of course, and you're not using an existing file)
Solution 2:[2]
did you try this , i fixed the same error by setting the expression between '' and the values between ""
cat explorer/connection-profile/test-network.json | jq '.organizations.Org1MSP.adminPrivateKey.path |= "44ab"'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shawn |
Solution 2 | himnabil |