Given the Goessner example JSON:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
I can get the highest price for a book using the following query:
$.max($.store.book[*].price))
.
Response: 22.99
.
If I query for this price: $.store.book[?(@.price ==22.99)]
Response:
[
{
"category" : "fiction",
"author" : "J. R. R. Tolkien",
"title" : "The Lord of the Rings",
"isbn" : "0-395-19395-8",
"price" : 22.99
}
]
But trying to inline the max expression into the query only gives a syntax error:
$.store.book[?(@.price ==$.max($.store.book[*].price)))]
Is this possible in a single JSONPath query?
In Jayway JSONPath Functions can be invoked at the tail end of a path
$.store.book[?(@.price == $..book[*].price.max())]
Online Tool : https://jsonpath.herokuapp.com/
Note : may not work with other implementations.