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

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
jq select multiple elements from an array - Unix & Linux Stack Exchange
You forgot to filter the compontents array when selecting for Redundant System ROM. A corrected variant of your code with some shortcuts added (note that -r is unneeded as you are outputting JSON, not raw strings): jq '.members[] | { serverName, "system-firmware": .components[] | ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
November 27, 2024
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 · 0 Extracting two (or more) related values from ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
September 17, 2022
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
🌐
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.
🌐
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 ·
🌐
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))'
🌐
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
gist.github.com › olih › f7437fb6962fb3ee9fe95bda8d2c8fa4
jq Cheet Sheet · GitHub
https://jqplay.org/s/rk2-UauouuV · Copy link · Copy Markdown · Puzzle: how do I go from this: { "widgets": [ { "name": "foo", "properties": [ "baz" ] }, { "name": "bar" } ] } to this · { "widgets": [ { "name": "foo", "properties": [ "baz", "boo" ] }, { "name": "bar" } ] } Or, is it possible to I add an item into an internal array? Copy link · Copy Markdown · @notorand-it Try this: . as $root | ($root.widgets[] | select(.name != "foo")) as $others | ($root.widgets[] | select(.name == "foo") * { properties: (.properties + ["boo"])}) as $newfoo | $root * { widgets: ([$newfoo] + [$others]) } I'm pretty sure it can be done some more sophisticated way, but this works too and is easy to understand.
🌐
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.

🌐
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 · | jq '.DATA | .[2]' { "TYPE": "slave", "AXFR_IPS": "none", "DOMAIN": "domain2.net", "TTL_SEC": 0, "SOA_EMAIL": "", "DOMAINID": 22222, "DESCRIPTION": "", "EXPIRE_SEC": 0, "RETRY_SEC": 0, "STATUS": 1, "LPM_DISPLAYGROUP": "", "REFRESH_SEC": 0 },
Published   May 22, 2014
Author   ghost
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/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!

🌐
Baeldung
baeldung.com › home › web › guide to linux jq command for json processing
Guide to Linux jq Command for JSON Processing | Baeldung on Linux
August 31, 2025 - Note that in these two examples, we’ve constructed a new array, using [] around the array iteration. This contains only the prices before we pass this new list to the min or max function. The select function is another impressive utility that we can use for querying JSON. We can think of it as a bit like a simple version of XPath for JSON: ... This selects all the fruit with a price greater than 0.5. Likewise, we can also make selections based on the value of a property: ... $ jq '.[] | to_entries[] | select(.key | startswith("name")) | .value' fruits.json "apple" "banana" "kiwi"
🌐
Technicus
techblog.jeppson.org › home › jq select specific value from array
JQ select specific value from array - Technicus
March 31, 2020 - jq -r '.Reservations[].Instances[].Tags[] | select (.Key == "EC2.Tag.Name").Value' jsonfile.json · The above query grabs all the tags (an array of Key,Value lines), then searches the result for a specific key “EC2.Tag.Name” and returns the Value line associated with it.