Consider
$ keys='[["key1","a"],["key2","b"]]' jq -c --argjson keys "$keys" '.[] | [getpath($keys[])]' <<<$'[{"key1":{"a":1},"key2":{"b":2}}] [{"key1":{"a":3},"key2":{"b":4}}]'
I expect output
[1,2]
[3,4]
But I seem to doing something wrong when defining argjson. I get error:
jq: invalid JSON text passed to --argjson
What am I doing wrong? Thanks!
You are either missing a semi-colon (or equivalent), or misunderstanding shell variables.
keys='[["key1","a"],["key2","b"]]' ; jq -c -n --argjson keys "$keys" '$keys'
keys='[["key1","a"],["key2","b"]]' jq -c -n 'env.keys | fromjson'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With