jq iterating over null value

Created on 7 Nov 2015  路  4Comments  路  Source: stedolan/jq

I have something like from jq filter execution

[
"sandbox1.blah.com"
]
null
[
"prod1.blah.com"
]

it's generated when I pipe the curl to | ./jq-linux64 .test[].dc1

when I do .test[].dc1[]

I get

"sandbox1.blah.com"
"prod1.blah.com"
jq: error (at :0): Cannot iterate over null (null)

also how can I do so that output is without double quotes.

Thanks in advance

Most helpful comment

using []? to handle that, works

All 4 comments

using []? to handle that, works

also how can I do so that output is without double quotes.

Use the -r option like this:

jq -r .test[].dc1[]

using []? to handle that, works

You saved my day.

Thank you!
jq -r '.[]?
Working for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sonots picture sonots  路  3Comments

rubensayshi picture rubensayshi  路  3Comments

ve3ied picture ve3ied  路  4Comments

rclod picture rclod  路  4Comments

tbelaire picture tbelaire  路  4Comments