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
.members[]Produces four outputs, one per member.| .nameEach output flows into the next filter, which readsname…| ascii_upcase…and on into the next, which upper-cases the string.
Result
"ADA" "LINUS" "GRACE" "ALAN"
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.