tools / json / jmespath / jmespath: extract values from nested arrays
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

InputResult
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

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?