Use slurp mode:

  o   --slurp/-s:

      Instead of running the filter for each JSON object
      in the input, read the entire input stream into a large
      array and run the filter just once.
$ jq -s '.' < tmp.json
[
  {
    "name": "John",
    "email": "[email protected]"
  },
  {
    "name": "Brad",
    "email": "[email protected]"
  }
]
Answer from chepner on Stack Overflow
🌐
Programming Historian
programminghistorian.org › en › lessons › json-and-jq
Reshaping JSON with jq | Programming Historian
May 24, 2016 - By adding [] onto the end of our filter, jq will break up this one array into 10 separate objects: ... Notice that the [] wrapping our results are now gone. To make clear what has happened, check the “Compact Output” checkbox in the upper right. This removes the cosmetic line breaks in the results, returning one JSON object per line.
Discussions

bash - Add JSON objects to array using jq - Unix & Linux Stack Exchange
It strips off everything in the pathname up to the last slash for the name value, and uses the pathname as is for the path value. The final jq reads the data from find into an array with -s, and simply inserts it as the items array in a new JSON object. More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 26, 2020
Creating an array from objects?
First of all, kudos on such an ... used jq for basic CLI tasks and have only recently delved into its more advanced functions, and am continually amazed at how things just work with few surprises...rare for a CLI tool that has so many features... So I think my question is pretty basic, and I'm missing something very obvious that could be clarified in the docs. Given a series of objects, what do I pipe them through to get them into an array? I've found I can do this: cat some.json | jq '.[] ... More on github.com
🌐 github.com
7
January 29, 2015
bash - Parsing a JSON array with jq - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I need to parse out specific information from the following JSON example bellow using jq. depending on the 'repo' I need to be able to parse from the properties array all 'key' & 'values' and ... More on stackoverflow.com
🌐 stackoverflow.com
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. More on stackoverflow.com
🌐 stackoverflow.com
🌐
iO Flood
ioflood.com › blog › jq-array
Manipulating JSON Arrays with jq | Example Guide
November 15, 2023 - Continue reading for a more detailed guide, complete with code examples and explanations. ... jq, being a powerful command-line JSON processor, allows you to create, access, and modify arrays with ease.
🌐
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 › 684
Creating an array from objects? · Issue #684 · jqlang/jq
January 29, 2015 - First of all, kudos on such an excellent library...I've used jq for basic CLI tasks and have only recently delved into its more advanced functions, and am continually amazed at how things just work with few surprises...rare for a CLI tool that has so many features... So I think my question is pretty basic, and I'm missing something very obvious that could be clarified in the docs. Given a series of objects, what do I pipe them through to get them into an array? I've found I can do this: cat some.json | jq '.[] | { attr1, attr2 }' | jq --slurp '.'
Author   dannguyen
🌐
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 - $ echo '{ "with space": "hello" }' | jq '."with space"' Let’s now look at how we can work with arrays in JSON data. We typically use arrays to represent a list of items. And as in many programming languages, we use square brackets to denote the start and end of an array. We’ll start with a basic example to demonstrate how to iterate over an array: ... Here, we see the object value iterator operator.[] in use, which will print out each item in the array on a separate line:
🌐
Baeldung
baeldung.com › home › files › file editing › how to add objects into json array using jq
How to Add Objects Into JSON Array Using jq | Baeldung on Linux
March 18, 2024 - The $inputs[] construct effectively concatenates the contents of inputs as a flat array directly into posts in blog.json. This results in a single array. In this article, we explored the various ways we can add an object to a JSON array using jq.
🌐
Compciv
compciv.org › recipes › cli › jq-for-parsing-json
Parsing JSON with jq
January 21, 2015 - Ernst, we were dealing with single Congressmember objects. This legislators.json contains an array of those Congressmember objects. So this query to find the name attribute will fail: user@host:~$ cat legislators.json | jq '.name' jq: error: Cannot index array with string
🌐
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!

🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-transform-json-data-with-jq
How To Transform JSON Data with jq | DigitalOcean
September 23, 2025 - When working with JSON input, jq can help you perform a wide variety of data transformations that would be difficult with text manipulation tools like sed. In this comprehensive tutorial, you learned fundamental operations like filtering data with the select function, transforming array elements with map, summing arrays of numbers with the add filter, and merging transformations into new data structures.
🌐
Earthly
earthly.dev › blog › jq-select
JQ Select Explained: Selecting elements from JSON with Examples - Earthly Blog
July 24, 2023 - jq lets you select elements by starting with a . and accessing keys and arrays like it’s a JavaScript Object (which is it is). This feature uses the Object and Array index jq creates of a JSON document and look like this:
🌐
Adamsdesk
adamsdesk.com › posts › count-json-array-elements-jq
How To Count JSON Array Elements with JQ
September 5, 2025 - This example queries the Mastodon account Adamsdesk profile metadata on Fosstodon using the Mastodon API and then will count the total array elements found under the “emojis” key. $ curl "https://fosstodon.org/api/v1/accounts/lookup?acct=adamsdesk" | jq '.emojis | length' ... For illustration purposes here are the contents of the query data with the beginning and end truncated so that only the “emojis” data is shown.
🌐
GitHub
gist.github.com › olih › f7437fb6962fb3ee9fe95bda8d2c8fa4
jq Cheet Sheet · GitHub
-> % jq '[path(..)] | .[3] ' example.json [ "data", "object", "user" ] (ehsm-py3.9) cbongior@cbongior-mac [09:54:38] [~/dev/ehsm] [main *] -> % jq 'getpath([ "data", "object", "user" ])' example.json { "id": 1, "range": [ -255, 0, 255 ], "notation": "big-O", "details": { "lat": 0.000, "long": 0.000, "time": 42 } } (ehsm-py3.9) cbongior@cbongior-mac [09:55:03] [~/dev/ehsm] [main *] -> % jq '[path(..)] | .[3] | getpath' example.json jq: error: getpath/0 is not defined at <top-level>, line 1: [path(..)] | .[3] | getpath jq: 1 compile error (ehsm-py3.9) cbongior@cbongior-mac [09:55:25] [~/dev/ehsm