JSONPath · lesson 10 of 13 · Filters
Existence tests
A bare path inside a filter tests whether it exists — no comparison needed. Put ! in front to test that it doesn't.
Examples
Example 1Books that have an ISBN
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[?@.isbn].title@.isbnTrue when the element has anisbnmember at all.
Result
"Moby Dick" "The Lord of the Rings"
Example 2Books without one
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]].title[email protected]The opposite: the element has noisbnmember.
Result
"Sayings of the Century" "Sword of Honour"