You can use jq '.[] | .login, .id' to obtain each login followed by its id.

Answer from user3899165 on Stack Overflow
🌐
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.
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
March 1, 2022
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
🌐 github.com
15
2
December 10, 2023
how to use jq to extract multiple text" node which are in a big nested json
You could try something like: jq -r '..|.text?' That will recurse down the structure and try and find all instances of "text". You'll get NULL back when an element doesn't contain "text" and the value of "text" if it does. More on reddit.com
🌐 r/bash
4
1
March 21, 2022
Is it possible to output multiple values on a single line?
jq '.object1,.object2,.object3' returns the value for these objects each on a new line: "value1" "value2" "value3" Is there an option, or some filter to output these values on a single line, sepera... More on github.com
🌐 github.com
18
May 12, 2015
🌐
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] ) ] | .[]'
🌐
Earthly
earthly.dev › blog › jq-select
JQ Select Explained: Selecting elements from JSON with Examples - Earthly Blog
July 24, 2023 - $ echo '[{"a":"b"},{"a":"c"}]' | jq -r '.[].a' b c · To turn these values into a JSON array, what you do is similar to creating an array in JavaScript: You wrap the values in an array constructor ([...]). ... The GitHub issues API has a lot of details I don’t care about. I want to select multiple fields from the returned JSON document and leave the rest behind.
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
🌐
Qmacro
qmacro.org › blog › posts › 2022 › 05 › 28 › multiple-level-filters-in-jq
Multiple level filters in jq
May 28, 2022 - select(.UnitsInStock <= 15) the value of the Products property is an array, because the navigation property between the Suppliers and Products entity types is defined as a one-to-many. This means it's appropriate to use another select filter to pick out specific elements (those with a value of 15 or less for the UnitsInStock).
Find elsewhere
🌐
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.
🌐
Lekkimworld
lekkimworld.com › 2018 › 09 › 07 › jq-and-multi-field-output-to-csv
jq and multi-field output to CSV – lekkimworld.com
September 7, 2018 - $ sfdx force:schema:sobject:describe -s Account -u myorg --json | jq -r ".result.fields[] | .label, .name" Age Age__pc PO Box PO_Box__pc Postal Code Before City Postal_Code_Before_City__pc Street No Before Street Street_No_Before_Street__pc Archived State Archived_State__pc
🌐
Sandbox
sandbox.bio › tutorials › jq-intro › 4
JSON wrangling with jq - sandbox.bio
Interactive jq tutorial: learn to filter and wrangle JSON files using a command-line interface in your browser.
🌐
Programming Historian
programminghistorian.org › en › lessons › json-and-jq
Reshaping JSON with jq | Programming Historian
May 24, 2016 - In the previous example we combined group_by() with join() to collect multiple values into a text field. However, we can also use group_by() in conjunction with length to compute new values. In this final exercise, we will use jq to count the number of times unique hashtags appear in this dataset.
🌐
Bashoneliners
bashoneliners.com › oneliners › 332
Printing with jq multiple values in CSV or TSV formats | bashoneliners.com
October 13, 2023 - curl -s 'https://api.github.com/orgs/github/repos' | jq -r '.[] | [.id, .name, .stargazers_count] | @csv'
🌐
jq recipes
remysharp.com › drafts › jq-recipes
jq recipes
April 16, 2024 - Converting a text output of columns and converting to a JSON object. In this case, running Zeit's now ls | jq --raw-input --slurp to find out how many running instance I have: split("\n")[1:-3] | # split into an array of strings, removing the 1st and last few blank lines map([ split(" ")[] | select(.
🌐
jQuery UI
jqueryui.com › datepicker
Datepicker | jQuery UI
Select a date from a popup or inline calendar · Default functionality · Animations · Dates in other months · Display button bar · Display inline · Display month & year menus · Display multiple months · Format date · Icon trigger · Localize calendar · Populate alternate field ·
🌐
Reddit
reddit.com › r/bash › how to use jq to extract multiple text" node which are in a big nested json
r/bash on Reddit: how to use jq to extract multiple text" node which are in a big nested json
March 21, 2022 -

User can fill out a textarea in form, and the json behind the scene is like this.What user entered is in "text" fields, (for example text = sample text 1), and there are multiple in this case. and it's dynamic. In other word, next day when user enter a lot of information, it will have much more "text" field in json.

#/comments/0/body/content/0/content/0/text

#/comments/0/body/content/1/content/0/content/0/content/0/text

#/comments/0/body/content/1/content/0/content/1/content/0/content/0/content/0/text

I want to extract these word out, how can I do it using jq?

{

"content": [

{

"type": "paragraph",

"content": [

{

"type": "mention",

"attrs": {

"id": "123",

"text": "sample text 1",

"accessLevel": ""

}

},

{

"type": "text",

"text": " sample text 2."

}

]

},

{

"type": "paragraph",

"content": [

{

"type": "mention",

"attrs": {

"id": "456",

"text": "sample text 3",

"accessLevel": ""

}

},

{

"type": "text",

"text": " "

},

{

"type": "mention",

"attrs": {

"id": "789",

"text": "sample text 4",

"accessLevel": ""

}

},

{

"type": "text",

"text": " "

}

]

}

]

}

🌐
iO Flood
ioflood.com › blog › jq-select
The jq 'select' Command | Your Key to JSON Data Filtering
November 16, 2023 - This includes using different conditions and combining jq ‘select’ with other jq commands for more sophisticated data filtering. You can use multiple conditions in your jq ‘select’ command to further refine your data filtering.
🌐
GitHub
github.com › jqlang › jq › issues › 785
Is it possible to output multiple values on a single line? · Issue #785 · jqlang/jq
May 12, 2015 - jq '.object1,.object2,.object3' returns the value for these objects each on a new line: "value1" "value2" "value3" Is there an option, or some filter to output these values on a single line, sepera...
Published   May 12, 2015
Author   Reino17
🌐
Medium
kannappanchidambaram.medium.com › understanding-jq-a-guide-to-processing-and-filtering-json-data-2af8b5ec84cf
Understanding jq: A Guide to Processing and Filtering JSON Data | by Kannappan Chidambaram | Medium
December 3, 2023 - From this JSON if we need to fetch selected fields (i.e. id, first_name, avatar fields ) from the data array and select only the id having even numbers then The filter we need to use is `select(expr)` like in the below - jq '.data[] | {id,first_name, avatar} | select(.id % 2 == 0)' sample.json