You can use jq '.[] | .login, .id' to obtain each login followed by its id.
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
How do I select multiple keys for output?
This seems like a basic question but I can't find examples anywhere in the documentation. If I have input like - alpha: 1 beta: foo gamma: 0.3 delta: bar - alpha: 2 beta: baz gamma: 1.23 delta: buz... More on github.com
jq select multiple elements from an array - Unix & Linux Stack Exchange
2 Using multiple wildcards in jq to select objects in a JSON file More on unix.stackexchange.com
json - Get field and nested field at the same time using jq - Unix & Linux Stack Exchange
> cat rm111.json | jq -r '.issues[] | .key .fields.summary' jq: error (at :18): Cannot index string with string "fields" I need to iterate over issues[] because there may be more than the one shown in this example. ... As a list of tab-separated values: Create an array of the wanted ... More on unix.stackexchange.com
json - jq select value from array - Stack Overflow
I'm also on the cat file.json side ... and filter commands all piped together and that jq is just the last part of a bigger equation. 2024-11-28T23:35:07.643Z+00:00 ... The question was about selecting a specific field based on value of other field.... More on stackoverflow.com
jq
jqlang.org › manual
jq 1.8 Manual
A jq program is a "filter": it takes an input, and produces an output. There are a lot of builtin filters for extracting a particular field of an object, or converting a number to a string, or various other standard tasks. Filters can be combined in various ways - you can pipe the output of one filter into another filter, or collect the output of a filter into an array. Some filters produce multiple results, for instance there's one that produces all the elements of its input array.
GitHub
gist.github.com › olih › f7437fb6962fb3ee9fe95bda8d2c8fa4
jq Cheet Sheet · GitHub
Installing from the source proved to be tricky. 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?
Mark Needham
markhneedham.com › blog › 2021 › 05 › 19 › jq-select-multiple-keys
jq: Select multiple keys | Mark Needham
May 19, 2021 - And then to flatten it out into single arrays instead of nested ones, we can pipe the result through the .[] selector: cat swagger-clean.json | jq -r '.paths | keys[] as $k | [ (.[$k] | keys[] as $k1 | [$k, $k1, .[$k1].operationId, .[$k1].summary] ) ] | .[]'
Gunnar Morling
morling.dev › blog › extracting-and-propagating-multiple-values-with-jq
Shell Spell: Extracting and Propagating Multiple Values With jq - Gunnar Morling
July 6, 2024 - jq is invaluable for handling JSON and I highly recommend spending some time with its reference documentation to learn about it. For the case at hand, the select() function is used within a pipeline for finding the right elements within the array of Terraform child modules and extracting the required values.
CopyProgramming
copyprogramming.com › howto › jq-select-multiple-fields-from-array
Mastering jq: Selecting Multiple Fields from Arrays and 2026 Best Practices - Jq select multiple fields from array
November 21, 2025 - The pick() function provides the most elegant solution for multiple field selection in jq 1.7 and later. Apply it directly to array elements: .[] | pick(.login, .id, .title) extracts only the specified fields from each object.
Stedolan
stedolan.github.io › jq › manual
Redirecting to jqlang.github.io
Redirecting to jqlang.github.io
Qmacro
qmacro.org › blog › posts › 2022 › 05 › 28 › multiple-level-filters-in-jq
Multiple level filters in jq - DJ Adams
May 28, 2022 - Then I loaded it into ijq, the lovely interactive frontend to jq, and played around a bit. ... .value gives me the entire array of objects in the dataset, each one of which represents a supplier with all their products · map(...) this outer map takes the array of supplier and product data and produces a new array, having processed each array element (each supplier with their products) with the filter expression supplied · select(.Country == "UK") this is the equivalent of the $filter=Country eq UK in the OData URL
QC 4Blog
qc4blog.com › home › using jq to select multiple fields from json data
JQ Select Multiple Fields: A Comprehensive Guide
March 22, 2024 - Let’s say we only want to select the first pet from our pets array. We can do that by using the index of the element as follows: ... We can also combine multiple filters to narrow down our selection even further. For example, if we want to select all pets with names longer than 5 characters, we can use the following command: jq ‘.pets[] | select(.name | length > 5)’ data.json ... Now that we’ve covered the basics of selecting multiple fields ...
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.
HackingNote
hackingnote.com › en › cheatsheets › jq
Cheatsheet - jq
Multiple fields: # from top level $ cat file.json | jq '. | {field1, field2}' # from sub level $ cat file.json | jq '.results[] | {id, name}' Extract as text values instead of JSON (getting rid of quotes), use -r: $ cat file.json | jq -r '.a.b[0].c' Slice an array · $ echo '["a", "b", "c", "d"]' | jq '.[1:3]' # get "name" of id 1 $ cat file.json | jq '.results[] | select(.id == "1") | {name}' # get result with multiple filters $ cat file.json | jq '.results[] | select((.id == "1") and (.name="a"))' # filter with substrings $ cat file.json | jq '.results[] | select(.name | contains("ab"))' # filter with regex $ cat file.json | jq '.results[] | select(.name | test("Joe\s+Smith"))' Given a list (items[]), find the item according to .spec.foo, change the value of .spec.bar to baz: cat file.json | jq '(.items[] | select(.spec.foo == "key")).spec.bar |= "baz"' Selectors start with ..
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"