JMESPath · lesson 8 of 15 · Filtering
&&, || and !
&& (and), || (or) and ! (not) combine tests inside a filter.
Examples
Example 1Both must hold
Document
{
"team": "Platform",
"office": { "city": "Berlin", "floor": 3 },
"members": [
{ "name": "Ada", "age": 36, "role": "lead", "active": true,
"email": "[email protected]", "skills": ["rust", "sql"] },
{ "name": "Linus", "age": 28, "role": "dev", "active": true,
"email": null, "skills": ["c", "shell"] },
{ "name": "Grace", "age": 45, "role": "dev", "active": false,
"skills": ["cobol"] },
{ "name": "Alan", "age": 41, "role": "qa", "active": true,
"email": "[email protected]", "skills": [] }
]
}Query
members[?role == 'dev' && age > `30`].name
role == 'dev'The first test…&&…and…age > `30`…the second, both true →["Grace"].
Result
["Grace"]
Example 2Either may hold
Document
{
"team": "Platform",
"office": { "city": "Berlin", "floor": 3 },
"members": [
{ "name": "Ada", "age": 36, "role": "lead", "active": true,
"email": "[email protected]", "skills": ["rust", "sql"] },
{ "name": "Linus", "age": 28, "role": "dev", "active": true,
"email": null, "skills": ["c", "shell"] },
{ "name": "Grace", "age": 45, "role": "dev", "active": false,
"skills": ["cobol"] },
{ "name": "Alan", "age": 41, "role": "qa", "active": true,
"email": "[email protected]", "skills": [] }
]
}Query
members[?age > `40` || role == 'lead'].name||True when at least one side is: older than 40, or the lead.
Result
["Ada","Grace","Alan"]
Good to know
!negates a test:members[?!active].namereturns["Grace"]. Parentheses group tests.