Found the answer:

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

json - jq: how to filter an array of objects based on values in an inner array? - Stack Overflow
I'm trying to construct a filter with jq that returns all objects with Ids that do not contain "data" in the inner Names array, with the output being newline-separated. For the above data, the output I'd like is: cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2b a4b7e6f5752d8dcb906a5901f7ab82e403b9dff4eaaeebea767a04bac4aada19 ... but the select ... 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
json - How to select items in JQ based on value in array - Stack Overflow
1 jq library: compare string from an array to a bash variable(not static value) 1 Exclude object if sub array contains n occurrences of a string with jq More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
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!

🌐
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.
🌐
Earthly
earthly.dev › blog › jq-select
JQ Select Explained: Selecting elements from JSON with Examples - Earthly Blog
July 24, 2023 - It’s similar to the WHERE clause in a SQL statement or array filter in JavaScript. Like map, I find select comes up quite a bit, so while you may have to come back to this article or google it the first few times you need it, with luck, it will start to stick to your memory after that. ... curl https://api.github.com/repos/stedolan/jq/issues?per_page=100 | \ jq 'map({ title: .title, number: .number, labels: .labels | length }) | map(select(.labels > 0))'
🌐
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 ·
🌐
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.
Find elsewhere
🌐
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
I can easily select a specific element in the sequence with · or select all specific subelements
Published   May 22, 2014
Author   ghost
🌐
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?
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
🌐
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"
🌐
Technitribe
blog.lnx.cx › 2019 › 09 › 09 › using-jq-to-filter-an-array-of-objects-from-json.html
Using jq to filter an array of objects from JSON | Technitribe
September 9, 2019 - $ jq -c '.prefixes[] | select(.service=="AMAZON")' < ip-ranges.json | head {"ip_prefix":"18.208.0.0/13","region":"us-east-1","service":"AMAZON"} {"ip_prefix":"52.95.245.0/24","region":"us-east-1","service":"AMAZON"} {"ip_prefix":"99.77.142.0/24","region":"ap-east-1","service":"AMAZON"}