PaesslerAG / jsonpath

BSD 3-Clause "New" or "Revised" License
172 stars 37 forks source link

Multi conditional jsonpath expression #13

Closed moshevi closed 5 years ago

moshevi commented 5 years ago

Hi. Is there a way to construct a single jsonpath expression that has multiple condition parts. If I have this JSON: {"a":1,"b":[{"x":2,"y":3},{"x":3,"y":2}]} And want to check that (a==1) AND (b[0].x==2 OR b[1].y==2) returns true, is there a single jsonpath expression that evaluate that (Instead of making multiple expressions and run each of them sequentially with AND/OR by code) ? Thanks.

generikvault commented 5 years ago

Hi,

yes propositional logic is included into gval. You can use && and ||. Take a look at the godoc: https://godoc.org/github.com/PaesslerAG/gval#PropositionalLogic

moshevi commented 5 years ago

@generikvault Do you familiar with that? Can you give me the expression to fulfil want I wanted on my issue? Thanks.

generikvault commented 5 years ago

($.a==1) && ($.b[0].x==2 || $.b[1].y==2) should do the job.