tools / json / jmespath / jmespath: built-in functions cheatsheet
json query · jmespath

JMESPath functions reference

JMESPath has ~30 built-in functions: math (min/max/sum/avg), string (starts_with/contains/lower), array (sort/reverse/length), and type (type/to_string).

intermediate jmespath / aws cli

The query

{count: length(users), avg_age: avg(users[*].age), names_csv: join(', ', sort(users[*].name))}

Pass / fail

InputResult
Input: {"users":[{"name":"Bo","age":30},{"name":"Ada","age":40}]}passes
Output: {"count": 2, "avg_age": 35.0, "names_csv": "Ada, Bo"}passes
users[*].age.avg() (NOT method-style — JMESPath uses prefix functions)fails
length users (MISSING PARENTHESES)fails

Edge cases & caveats

All functions are prefix-call: `func(arg1, arg2)`. Some take expression refs: `sort_by(@, &age)`. Math functions only accept numeric arrays — `avg(["1","2"])` errors. Convert with `to_number(@)` first.

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

minify json (smallest valid output) · chain expressions with pipes · build a flat list from multiple fields · filter an array by condition