Learn JMESPath
Projections, filters and built-in functions — the language behind the AWS CLI's --query.
Basics
- Identifiers & missing values A JMESPath expression is a path: office.city reads city inside office, with no leading . or $. A key that…
- Array indexes [n] selects an element (zero-based); a negative number counts from the end.
Projections
- Slices [start:end:step] works like a Python slice: the end is exclusive, negative numbers count from the end, and…
- Projections: [*] and * [*] is JMESPath's central idea: a projection applies everything to its right to each element and gathers the…
- Flatten: [] [] flattens one level of nesting — and, like [*], it starts a projection.
- Pipes stop projections After a projection, everything to its right runs on each element. A pipe | ends the projection, so what…
Filtering
- Filters & literals [?condition] keeps the elements for which the condition is true. Numbers, booleans and null are written as…
- &&, || and ! && (and), || (or) and ! (not) combine tests inside a filter.
- Functions in filters Any function can appear in a condition, which is how you test text and arrays.
Reshaping
- Multiselect list [a, b, c] builds a list from several expressions — JMESPath's counterpart to jq's comma.
- Multiselect hash {key: expression, …} builds an object, so you can rename, pick and combine values.
Functions
- Counting & math length, avg, min, max and sum work on arrays (and length works on strings and objects too).
- Sorting & picking sort_by, min_by and max_by take an expression reference: &age means "evaluate age on each element" rather…
- Strings, join & map join(glue, list) builds a string, and map(&expr, list) applies an expression to every element.
- Types & defaults type names a value's type. a || b falls back to b when a is null, missing or empty, and not_null(a, b, …)…