JSONPath · lesson 9 of 13 · Filters
Combining conditions
&& (and), || (or) and ! (not) combine tests. Use parentheses to group.
Examples
Example 1Both must hold
Document
{
"store": {
"book": [
{ "title": "Sayings of the Century", "author": "Nigel Rees",
"category": "reference", "price": 8.95 },
{ "title": "Sword of Honour", "author": "Evelyn Waugh",
"category": "fiction", "price": 12.99 },
{ "title": "Moby Dick", "author": "Herman Melville",
"category": "fiction", "price": 8.99, "isbn": "0-553-21311-3" },
{ "title": "The Lord of the Rings", "author": "J. R. R. Tolkien",
"category": "fiction", "price": 22.99, "isbn": "0-395-19395-8" }
],
"bicycle": { "color": "red", "price": 19.95 }
}
}Query
$.store.book[?@.category == 'fiction' && @.price < 13].title
@.category == 'fiction'The first test…&&…and…@.price < 13…the second, both true.
Result
"Sword of Honour" "Moby Dick"
Example 2Either may hold
Document
{
"store": {
"book": [
{ "title": "Sayings of the Century", "author": "Nigel Rees",
"category": "reference", "price": 8.95 },
{ "title": "Sword of Honour", "author": "Evelyn Waugh",
"category": "fiction", "price": 12.99 },
{ "title": "Moby Dick", "author": "Herman Melville",
"category": "fiction", "price": 8.99, "isbn": "0-553-21311-3" },
{ "title": "The Lord of the Rings", "author": "J. R. R. Tolkien",
"category": "fiction", "price": 22.99, "isbn": "0-395-19395-8" }
],
"bicycle": { "color": "red", "price": 19.95 }
}
}Query
$.store.book[[email protected] < 9 || @.price > 20].title
||True when at least one side is: very cheap or very expensive.
Result
"Sayings of the Century" "Moby Dick" "The Lord of the Rings"