Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error jq: invalid JSON text passed to –argjson

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

jq: invalid JSON text passed to --argjson

What am I doing wrong? Thanks!

>Solution :

You are either missing a semi-colon (or equivalent), or misunderstanding shell variables.

  1. With the semicolon:
keys='[["key1","a"],["key2","b"]]' ; jq -c -n --argjson keys "$keys" '$keys'
  1. Using shell variables:
keys='[["key1","a"],["key2","b"]]' jq -c -n 'env.keys | fromjson'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading