Found the answer:

cat <file>.json | jq -r '.files[] | select(.fileName=="FOO") | .md5'
Answer from Marvin Effing on Stack Overflow
Discussions

Using jq, extract fields and subfields from a list of objects, grouping paired subfields for saving to csv - Unix & Linux Stack Exchange
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI ... 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
ndjson - How do I select multiple fields in jq? - Stack Overflow
You can use jq '.[] | .login, .id' to obtain each login followed by its id. ... Sign up to request clarification or add additional context in comments. ... The users' sample input does look like a stream of objects, but because of the sample script they provide, I'm assuming it's wrapped in an array ... More on stackoverflow.com
🌐 stackoverflow.com
json - jq convert an array by selecting to a list using only some values of the objects in the array - Unix & Linux Stack Exchange
jq '.fields |= (map({ (.name): .value }) | add)' file ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 3 use jq to pick a key out of a list of a list of objects and raw output with newline separation for outer array items More on unix.stackexchange.com
🌐 unix.stackexchange.com
September 17, 2022
🌐
Earthly
earthly.dev › blog › jq-select
JQ Select Explained: Selecting elements from JSON with Examples - Earthly Blog
July 24, 2023 - jq lets you select the whole array [], a specific element [3], or ranges [2:5] and combine these with the object index if needed.
Top answer
1 of 2
4

You want to run a .context,.score filter on each element of v I think:

$ jq -r '.[] | [.c, .e, .score, (.v[] | .context,.score)] | @csv' file.json
"A","B",0.99,"asdf",0.98,"bcdfd",0.97

This is equivalent to using the builtin map function without assembling the results back into an array.

2 of 2
2

The following creates a JSON-encoded CSV record for each top-level array element, and then extracts and decodes them. For each of the top-level elements, the values of the sub-array is incorporated by "flattening" the array.

jq -r 'map([ .c,.e,.score, (.v|map([.context, .score])) ] | flatten | @csv)[]' file

Given a test document equivalent of the following:

[
   {
      "c": "A",
      "e": "B",
      "score": 0.99,
      "v": [
         { "context": "asdf", "score": 0.98, "url": "..." },
         { "context": "bcdfd", "score": 0.97, "url": "..." }
      ]
   },
   {
      "c": "A",
      "e": "B",
      "score": 0.99,
      "v": [
         { "context": "asdf", "score": 0.98, "url": "..." },
         { "context": "asdf", "score": 0.98, "url": "..." },
         { "context": "bcdfd", "score": 0.97, "url": "..." }
      ]
   },
   {
      "c": "A",
      "e": "B",
      "score": 0.99,
      "v": [
         { "context": "asdf", "score": 0.98, "url": "..." },
         { "context": "asdf", "score": 0.98, "url": "..." },
         { "context": "asdf", "score": 0.98, "url": "..." },
         { "context": "bcdfd", "score": 0.97, "url": "..." }
      ]
   }
]

... we get

"A","B",0.99,"asdf",0.98,"bcdfd",0.97
"A","B",0.99,"asdf",0.98,"asdf",0.98,"bcdfd",0.97
"A","B",0.99,"asdf",0.98,"asdf",0.98,"asdf",0.98,"bcdfd",0.97

One could also reorder the operations so that a single use of the @csv operator gets a set of arrays (rather than repeatedly using @csv on single arrays):

jq -r 'map([ .c,.e,.score, (.v|map([.context, .score])) ] | flatten)[]|@csv' file
🌐
Zendesk Developer Docs
developer.zendesk.com › documentation › integration-services › developer-guide › jq-cheat-sheet
jq cheat sheet | Zendesk Developer Docs
A jq expression consists one or more filters. Use an object identifier-index filter to get properties from a JSON object. The following expression extracts a ticket id from a nested ticket object. ... Use an array index filter to get elements from a JSON array.
🌐
Reddit
reddit.com › r/commandline › jq: extract element from object or array of objects
r/commandline on Reddit: jq: Extract element from object or array of objects
May 10, 2025 -

Given the following JSON, what is the best way to extract the phone numbers, whether inside an object or an array of objects?

{
  "phones": {
    "Alex Baker": { "location": "mobile", "number": "+14157459038" },
    "Bob Clarke": [
      { "location": "mobile", "number": "+12135637813" },
      { "location": "office", "number": "+13104443200" }
    ],
    "Carl Davies": [
      { "location": "office", "number": "+14083078372" },
      { "location": "lab", "number": "+15102340052" }
    ],
    "Drew Easton": { "location": "office", "number": "+18057459038" }
  }
}

I'm using the following query, but I wonder if there's a better way to do this:

$ cat phones.json | jq '.phones | to_entries | [ .[].value | objects | .number ] + [ .[].value | arrays | .[].number ]'
[
  "+14157459038",
  "+18057459038",
  "+12135637813",
  "+13104443200",
  "+14083078372",
  "+15102340052"
]

Any suggestions will be appreciated, thanks!

🌐
GitHub
gist.github.com › olih › f7437fb6962fb3ee9fe95bda8d2c8fa4
jq Cheet Sheet · GitHub
When running jq, the following arguments may become handy: ... Hi, I have an object and I would like to select from input_chunks all object where status.mem_size != "0b" I tried like this .[] | select(.status.mem_size!="0b") or .input_chunks | select(.status.mem_size!="0b") but it didn't work :( Maybe someone can help me?
🌐
jq
jqlang.org › manual
jq 1.8 Manual
These built-ins select only inputs that are arrays, objects, iterables (arrays or objects), booleans, numbers, normal numbers, finite numbers, strings, null, non-null values, and non-iterables, respectively. ... It's useful on occasion. You'll know if you need it :) ... Produces an error with the input value, or with the message given as the argument. Errors can be caught with try/catch; see below. ... Stops the jq program with no further outputs.
Find elsewhere
🌐
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 ... each array element using either jq '.response[] | objects | .text' file.json or jq '.response[] | select(type=="object" and has("text")) | .text' file.json ·...
🌐
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...
Published   May 22, 2014
Author   ghost
🌐
Luis Cacho
luiscachog.io › garden › jq-select-based-on-value
jq select objects based on a value | Luis Cacho
May 18, 2022 - jq '.DATA[] | select(.DOMAIN == ("domain2","domain3")) | .DOMAINID,.DOMAIN' 22222 "slave" 33333 "slave" # or jq '.DATA[] | select(.DOMAIN | IN("domain2", "domain3")) | .DOMAINID,.DOMAIN' 22222 "slave" 33333 "slave"
Top answer
1 of 1
5
jq '.fields |= ( map(.key = .name | del(.type,.linkedId,.name)) | from_entries )' file

This updates the fields array. First, for each element (using map()), a key key is created with the value from the name key. Then the type, linkedId, and name keys are deleted from the element. We are now left with a key and a value key in each element of the fields array, which is just what from_entries needs to associate the key values as keys to the value values.

Testing on the data given in the question (with a trailing comma removed), this generates the following JSON:

{
  "name": "Papanito",
  "fields": {
    "Name1": "Value1",
    "Name2": "Value2",
    "Name3": "Value3",
    "Name4": "Value3"
  }
}

Note that your expected output is invalid JSON, as an array can't have keys. Therefore, the fields value in the output above is an object, not an array.

Would you want to keep fields as an array, you could rearrange the operations a bit:

jq '.fields |= map([.key = .name | del(.type,.linkedId,.name)] | from_entries)' file

For the given data (corrected as mentioned above), this would generate something equivalent to the following document:

{
   "name": "Papanito",
   "fields": [
      { "Name1": "Value1" },
      { "Name2": "Value2" },
      { "Name3": "Value3" },
      { "Name4": "Value3" }
   ]
}

This has the benefit that two elements with the same original name values would not overwrite each other in the result.


Conceptually, the above deletes the data that we no longer want. The following variations extract the data we want instead.

This generates the last result from above:

jq '.fields |= map({ (.name): .value })' file

And we can get the first result (with fields as a single object) by merging the entries in the list:

jq '.fields |= (map({ (.name): .value }) | add)' file
🌐
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.