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.

Answer from peak on Stack Overflow
🌐
Exercism
exercism.org › tracks › jq › concepts › arrays
Arrays in jq on Exercism
Values are separated by , comma. Arrays can contain zero or more of any kind of JSON values.
Discussions

shell - Get value of JSON [] array in jq - Unix & Linux Stack Exchange
mykey=1645128900000 jq --argjson key "$mykey" '.[] | select(first == $key) | last' file · This selects all the array entries with the given key as its first element and then extracts the value, the last element, from each piece chosen. More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 17, 2022
Using JQ to return the index number where an element in an array has a specific value.
jq '[.Channels[].Channel_Short]|index("ch02")' Settings.json ? More on reddit.com
🌐 r/bash
8
7
July 27, 2023
How can I get jq to produce the array of values of a json dictionary? - Unix & Linux Stack Exchange
I would like to use jq to print out all of the values in this dictionary. More on unix.stackexchange.com
🌐 unix.stackexchange.com
jq: Extract element from object or array of objects
The shortest solution that comes to mind: jq '[..| objects | .number | select(. != null)]' phones.json which is a basic 4-element pipeline: recursive descent selecting only objects extracting their number value ignoring nulls (from generated objects that don't contain a `number field) Wrap it all up in an array, and Bob's your uncle. More on reddit.com
🌐 r/commandline
6
3
May 10, 2025
🌐
Zendesk Developer Docs
developer.zendesk.com › documentation › integration-services › developer-guide › jq-cheat-sheet
jq cheat sheet | Zendesk Developer Docs
The following expression converts an array of objects into a flat object. The new object uses the id value as a key for the previous object's value property.
🌐
GitHub
gist.github.com › olih › f7437fb6962fb3ee9fe95bda8d2c8fa4
jq Cheet Sheet · GitHub
Indeed, it works in jq version 1.7.1. Help much appreciated! ... to_entries[] | [ .value.chrom, .value.pos, (.value.alleles | keys[0]), (.value.alleles | keys[1:] | join(",")) ] | @tsv ... Seems you guys are expert. I can't find my way to do what I want. I have this json array:
🌐
Proinsias
proinsias.github.io › til › jq-getting-all-the-values-of-an-array
Jq: Getting all the values of an array - Looking for data in all the right places…
May 13, 2025 - You can extract the values of the text field from the array using jq: > jq '.response[].text?' file.json "blabla" "blabla2" "blabla3" Or you can select using the type of each array element using either jq '.response[] | objects | .text' file.json or jq '.response[] | select(type=="object" and has("text")) | .text' file.json ·
🌐
jq
jqlang.org › manual
jq 1.8 Manual
This option passes a JSON-encoded value to the jq program as a predefined variable. If you run jq with --argjson foo 123, then $foo is available in the program and has the value 123.
🌐
Programming Historian
programminghistorian.org › en › lessons › json-and-jq
Reshaping JSON with jq | Programming Historian
May 24, 2016 - In this object, the array only has one value, "Amsterdam", however it could have multiple values, e.g. ["Amsterdam", "Kloveniersdoelen"]. Remember, values of an array have no keys - they are all considered to be semantically equivalent to each other. For the bulk of this lesson, we will be ...
Find elsewhere
🌐
Reddit
reddit.com › r/bash › using jq to return the index number where an element in an array has a specific value.
r/bash on Reddit: Using JQ to return the index number where an element in an array has a specific value.
July 27, 2023 -

I managed to do this when I was teaching myself JSON and playing with JQ. Now I can't remember how I did this. So any guidance would be of value.

Take the following file: settings.json

{
  "Bot_API_Key": "SuperSecretKey",
  "Channels": [
    {
      "Channel_Name": "First Channel",
      "Channel_Short": "ch01",
      "Channel_ID": 4004841050681
    },
    {
      "Channel_Name": "Second Channel",
      "Channel_Short": "ch02",
      "Channel_ID": 4004685917007
    }
  ]
}

If I use the following:

jq '.Channels[] | contains("ch02")' settings.json

It returns:

false
true

What I actually need is the index number in the array. In this case it must return 1.

I did achieve this once, a few weeks back, when experimenting, and now I can't repeat the results. Like a fool, I didn't document everything I did.

🌐
Earthly
earthly.dev › blog › jq-select
JQ Select Explained: Selecting elements from JSON with Examples - Earthly Blog
July 24, 2023 - The only difference is you can use the object and array queries you’ve built up as the values. Returning to my GitHub API problem, to wrap the number and the title up into an array I use the object constructor like this: $ curl https://api.github.com/repos/stedolan/jq/issues?per_page=2 | \ jq '[ .[] | { title: .title, number: .number} ]'
🌐
jq recipes
remysharp.com › drafts › jq-recipes
jq recipes
April 16, 2024 - npm i $(echo $(npm outdated --json | jq -r 'to_entries | .[] | "\(.key)@\(.value.latest)"'))
🌐
jq
jqlang.org › manual › dev
jq Manual (development version)
This option passes a JSON-encoded value to the jq program as a predefined variable. If you run jq with --argjson foo 123, then $foo is available in the program and has the value 123.
🌐
jq
jqlang.org › tutorial
Tutorial
Streams are serialised by just separating JSON values with whitespace. This is a cat-friendly format - you can just join two JSON streams together and get a valid JSON stream. If you want to get the output as a single array, you can tell jq to "collect" all of the answers by wrapping the filter in square brackets:
🌐
Shapeshed
shapeshed.com › jq-json
JSON on the command line with jq | George Ornbo
September 19, 2024 - jq can retrieve values from this document by passing key names. ... Multiple keys can by passed separated by commas. ... To search for nested objects chain values using the dot operator just as you would in JavaScript.
🌐
Medium
staffeng.medium.com › jq-json-extract-arrays-4560c2dcf051
jq & JSON : extract arrays. Given this json, extract cpu array… | by Natarajan Santhosh | Medium
August 1, 2023 - Explanation: - `jq ‘.cpu | .user, .system, .duration, (.functions[] | .func, .duration) | @csv’ data.json`: This `jq` expression first accesses the `cpu` object using `.cpu`, then selects the fields `user`, `system`, and `duration` from the `cpu` object. Next, it uses `.functions[]` to iterate over each element in the `functions` array and selects the fields `func` and `duration` from each function object.
🌐
GitHub
github.com › jqlang › jq › issues › 370
selecting an array element, based on subelement value -> jq: error: Cannot index array with string · Issue #370 · jqlang/jq
my input is { "ACTION": "domain.list", "DATA": [ { "TYPE": "slave", "AXFR_IPS": "none", "DOMAIN": "domain1.com", "TTL_SEC": 0, "SOA_EMAIL": "", "DOMAINID": 11111, "DESCRIPTION": "", "EXPIRE_SEC": 0, "RETRY_SEC": 0, "STATUS": 1, "LPM_DISP...