getting all the values of an array with jq

Evidently one of the items in the array is a string. If your jq supports “?”, then one possibility would be to use it:

.response[].text?

Another would be to check the type explicitly, e.g.:

.response[] | objects | .text

Yet another possibility:

.response[] | select(type=="object" and has("text")) | .text

If you want to have a placeholder value when there is no “text” field:

 .response[] | if type=="object" and has("text") then .text else null end

So it really depends on your requirements and perhaps the version of jq that you are using.

Leave a Comment