This seems very much possible, but I can't get it to work. Could be my JSON or my jsonpath selector. Not sure.
Here's the simple JSON showing a book inventory with the cost of 10 and 20 copies, along with which ones are On Sale:
{
"Books": {
"1": {
"Title": "Title of the 1st book",
"Cost": {
"10": 19.95,
"20": 29.95
},
"OnSale": 0
},
"2": {
"Title": "Title of the 2nd book",
"Cost": {
"10": 9.95,
"20": 39.95
},
"OnSale": 1
},
"3": {
"Title": "Title of the 3rd book",
"Cost": {
"10": 5.95,
"20": 49.95
},
"OnSale": 0
}
},
"ChosenQuantity": "10"
}
Using the stefan.goessner jsonpath library, I want the cost of 10 books that are On Sale with the following jsonpath selector:
$.Books[?(@.OnSale==1)].Cost[?($.ChosenQuantity)]
I can't hard code any of the key values into the jsonpath selector.
With the above jsonpath, what I'm expecting:
[
9.95
]
Instead, I'm getting the following:
[
9.95,
39.95
]
To test, I've been using https://jsonpath.herokuapp.com/ with the Goessner implementation.
Is the problem in the JSON, the jsonpath selector filters, or both?