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

lylemoffitt picture lylemoffitt  路  44Comments

johan picture johan  路  45Comments

ghost picture ghost  路  69Comments

nicowilliams picture nicowilliams  路  23Comments

evert picture evert  路  58Comments