JsonPath and operator on an array

I have an array in JSON and I would like to apply two filters to it:

$ ._ embedded.values ​​[0] ._ embedded.data [? (@. var1 = 'value1' && @ .var2 = 'value2')]

I need to select only those elements from the array that satisfy operation I. However, in practice this does not work.

Is it possible to do this or should I perform a two-step action to retrieve one set and then filter again to get the final results?

+5
source share
2 answers

As far as I know, AND / OR is not yet supported. But you can relate relatively closely to this array [,]. But even that made me think when I tested it. There is strange behavior. I took an example JSON string from the Jayway JsonPath Evaluator and put it in the JsonPath Expression Tester (because it didn't work with Jayway when I tried).

So, the JSON I tested with the curiousconcept version:

{ "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": "JRR Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } }, "expensive": 10 } 

And the expression:

 $..book[?(@.price==8.99),?(@.category=='fiction')] 

that leads to:

 [ { "category":"fiction", "author":"Herman Melville", "title":"Moby Dick", "isbn":"0-553-21311-3", "price":8.99 } ] 

that seems perfect. (take the price 8.99 And the category is "fiction" ... perfect!)

BUT : change it to:

 $..book[?(@.category=='fiction'),?(@.price==8.99)] 

then output:

 [ ] 

It seems to me that [,] is not well implemented in the Jayway JsonPath Tester, as well as in the curiousconcept.com expression test.

But from what I know, they are working on a (real) implementation of AND and / or (issue27 here in Google code).

Hope this clears up at least something!

+1
source

The Jayway implementation supports built-in AND and OR criteria.

 $..book[?(@.price==8.99 && @.category=='fiction')] [ { "category" : "fiction", "author" : "Herman Melville", "title" : "Moby Dick", "isbn" : "0-553-21311-3", "price" : 8.99 } ] 

Try and compare different implementations here http://jsonpath.herokuapp.com/

+9
source

All Articles