tools / json / jmespath / jmespath: filter an array by condition
json query · jmespath

Filter a JSON array with JMESPath

Filter an array of objects to those matching a predicate. JMESPath uses bracket-syntax `[?expr]` — equivalent to JS `arr.filter()` or jq `select()`.

intermediate jmespath / aws cli

The query

users[?age >= `18` && active == `true`].name

Pass / fail

InputResult
Input: {"users":[{"name":"Ada","age":30,"active":true},{"name":"Bo","age":15,"active":true},{"name":"Cy","age":40,"active":false}]}passes
Output: ["Ada"]passes
users[?age > 18] (BARE NUMBER — must be backtick-quoted: `18`)fails
users[?name == "Ada"] (DOUBLE QUOTES — strings need single quotes: 'Ada')fails

Edge cases & caveats

Backticks `` ` `` quote literals (numbers, booleans, null). Single quotes `'...'` quote strings. Double quotes are NOT valid for literals. Compound conditions use `&&`, `||`, `!`. Comparison: `==`, `!=`, `<`, `<=`, `>`, `>=`.

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

pretty-print json (formatted output) · chain expressions with pipes · build a flat list from multiple fields · validate json against a schema