json query · jmespath
Pipe operator in JMESPath
Pipe `|` ends one query and starts another — useful when you want to apply an operation to the result of a projection rather than each element.
advanced
jmespath / aws cli
The query
users[?active].[name, email] | sort_by(@, &[0])
Pass / fail
| Input | Result |
|---|---|
| Input: {"users":[{"name":"Bo","email":"b","active":true},{"name":"Ada","email":"a","active":true},{"name":"Cy","email":"c","active":false}]} | ✓passes |
| Output: [["Ada","a"],["Bo","b"]] | ✓passes |
| users[?active].[name,email].sort_by(...) (sort_by applies PER-ELEMENT, not on full result) | ✗fails |
Edge cases & caveats
Pipe `|` is the way to apply a function to the FULL projected result rather than each element. `&` is the expression-reference operator — used inside functions like `sort_by(@, &age)` to declare 'sort by the age key'.
Common use cases
- Sorting filtered results
- Limiting to top-N after projection
- Aggregating across projection
- Multi-step data shaping in single query
Run JMESPath against piped JSON
jsonyo is the CLI twin of the jsonyo browser extension — validate against schemas, format, run JMESPath queries against piped JSON. Zero deps.
Open jsonyo
Related
minify json (smallest valid output) · built-in functions cheatsheet · build a flat list from multiple fields · filter an array by condition