jq · lesson 5 of 32 · Pipes & building output

Pipes

| feeds each output of the filter on its left into the filter on its right. It is how small filters combine into a program.

Examples

Example 1Names, upper-cased

Document

{
  "team": "Platform",
  "office": { "city": "Berlin", "floor": 3 },
  "members": [
    { "name": "Ada", "age": 36, "role": "lead", "active": true,
      "email": "[email protected]", "skills": ["rust", "sql"] },
    { "name": "Linus", "age": 28, "role": "dev", "active": true,
      "email": null, "skills": ["c", "shell"] },
    { "name": "Grace", "age": 45, "role": "dev", "active": false,
      "skills": ["cobol"] },
    { "name": "Alan", "age": 41, "role": "qa", "active": true,
      "email": "[email protected]", "skills": [] }
  ]
}

Query

.members[] | .name | ascii_upcase
  1. .members[] Produces four outputs, one per member.
  2. | .name Each output flows into the next filter, which reads name…
  3. | ascii_upcase …and on into the next, which upper-cases the string.

Result

"ADA"
"LINUS"
"GRACE"
"ALAN"

Try it in the playground

Good to know

  • Read a pipeline left to right: | hands every output of its left side, one at a time, to its right side.
  • .a.b[0] and .a | .b | .[0] mean exactly the same thing.

About jsonquery

Query, format and learn JSON with jq, JSONPath, JMESPath and JSON Pointer. It is the engine of the desktop app, run in your browser.

Engine
The desktop app’s, compiled to WebAssembly
Licence
MIT (the engine and the app)
Source
GitHub
Contact
The contact form (private)
Public issues
GitHub
Legal
Privacy policy

Known limitations: a file over 10 MB opens read-only and one over 512 MB does not open here; the desktop app has no such limit.