json query · jmespath
Extract from nested JSON with JMESPath
Pull specific fields out of nested arrays in one expression — JMESPath's projection operator `[*]` flattens one level at a time.
advanced
jmespath / aws cli
The query
instances[*].tags[?Key == 'Env'].Value | [0]
Pass / fail
| Input | Result |
|---|---|
| Input: {"instances":[{"tags":[{"Key":"Env","Value":"prod"},{"Key":"Team","Value":"a"}]}]} | ✓passes |
| Output: "prod" | ✓passes |
| instances.tags[?Key == 'Env'].Value (MISSING [*] — won't iterate) | ✗fails |
| instances[*].tags.Key (CAN'T project across nested array without [*]) | ✗fails |
Edge cases & caveats
`[*]` is a wildcard projection — applies the rest of the expression to each element. Pipe `|` ends a projection (subsequent operations apply to the result, not each element). Common gotcha: forgetting the pipe = different results.
Common use cases
- AWS instance tag extraction (--query)
- Kubernetes resource field selection
- Cleaning nested API responses
- Reporting on deeply-nested config
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
built-in functions cheatsheet · flatten nested arrays · filter an array by condition · jmespath vs jq: which json query language?