json query · jmespath
Flatten arrays with JMESPath
Collapse one level of array nesting using `[]` (no inner expression). Equivalent to `arr.flat(1)` in JS.
intermediate
jmespath / aws cli
The query
regions[*].zones[]
Pass / fail
| Input | Result |
|---|---|
| Input: {"regions":[{"zones":["a","b"]},{"zones":["c"]}]} | ✓passes |
| Output: ["a", "b", "c"] | ✓passes |
| regions[*].zones (RESULT IS [[a,b],[c]] — NOT flattened) | ✗fails |
| regions[*].zones[*] (PROJECTION ON ZONES — slightly different semantics) | ✗fails |
Edge cases & caveats
Flatten `[]` only flattens ONE level. For deeper, chain: `[][]`. The difference between `[*]` (projection) and `[]` (flatten) is subtle but important — flatten merges, projection iterates.
Common use cases
- Combining results from multiple AWS regions
- Deduping nested log streams
- Aggregating per-pod metrics into a flat list
- Building unified resource inventories
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
extract values from nested arrays · validate json against a schema · minify json (smallest valid output) · built-in functions cheatsheet