JsonPath AND Operator on Array

Mike Chinaloy picture Mike Chinaloy · Apr 17, 2015 · Viewed 24.4k times · Source

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

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

I need to select only those elements from the array that satisfies the AND operation. However, in practice this doesn't appear to work.

Is it possible to do this or must I perform a two step action to extract one set then filter again to get my final results?

Answer

kalle picture kalle · Apr 20, 2015

The Jayway implementation supports inlined 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 it out and compare different implementations here http://jsonpath.herokuapp.com/