JSONPath · lesson 11 of 13 · Filters
Comparing with the rest of the document
Inside a filter, $ still means the document root, so an element can be compared with any other value in the document.
Examples
Example 1Books cheaper than the bicycle
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[?@.price < $.store.bicycle.price].title
@.priceThe book's own price.$.store.bicycle.priceAn absolute path back to the root: the bicycle's price,19.95.
Result
"Sayings of the Century" "Sword of Honour" "Moby Dick"