Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonPath AND Operator on Array

Tags:

jsonpath

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?

like image 447
Mike Chinaloy Avatar asked Apr 17 '15 15:04

Mike Chinaloy


1 Answers

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/

like image 198
kalle Avatar answered Oct 13 '22 22:10

kalle