Parenthesis in JSON filter node

If I have the following JSON:

`

{
“foo”: [
{
“a” : “x”,
“b” : 1
},
{
“a” : “y”,
“b” : 2
},
{
“a” : “z”,
“b” : 3
},
{
“a” : “a”,
“b” : 4
}
]
}

`

How would I achieve this logic: “foo.a in [x, y, z] AND foo.b == 1”?

I’ve tried:

`

$.foo[?((@.a == “x” || @.a == “y” || @.a == “z”) && @.b == 1)]

$.foo[?(@.a == “x” || @.a == “y” || @.a == “z”), ?(@.b == 1)]

$.foo[?(@.a == “x” || @.a == “y” || @.a == “z”) && ?(@.b == 1)]

`

Looking over the code, I don’t think parenthesis is supported?

By chance, I tried the following:

`

$.foo[?(@.a == “x” || @.a == “y” || @.a == “z”)][?(@.b == 1)]

// Raw query
[1.62] parsed: List(RootNode, Field(foo), BooleanFilter(OrOperator,ComparisonFilter(EqOperator,SubQuery(List(CurrentNode, Field(a))),JPString(x)),BooleanFilter(OrOperator,ComparisonFilter(EqOperator,SubQuery(List(CurrentNode, Field(a))),JPString(y)),ComparisonFilter(EqOperator,SubQuery(List(CurrentNode, Field(a))),JPString(z)))), ComparisonFilter(EqOperator,SubQuery(List(CurrentNode, Field(b))),JPLong(1)))

// Formatted query
[1.62] parsed:
List(
RootNode,
Field(foo),
BooleanFilter(
OrOperator,
ComparisonFilter(
EqOperator,
SubQuery(List(CurrentNode, Field(a))),
JPString(x)
),
BooleanFilter(
OrOperator,
ComparisonFilter(
EqOperator,
SubQuery(List(CurrentNode, Field(a))),
JPString(y)),
ComparisonFilter(
EqOperator,
SubQuery(List(CurrentNode, Field(a))),
JPString(z)))
),
ComparisonFilter(
EqOperator,
SubQuery(List(CurrentNode, Field(b))),
JPLong(1))
)

`

Which seems to work but seems like an unintended side-effect? I’m guessing it’s an “AND” operation therefore probably would not support “OR”.

Is this the proper way to achieve this or is there some alternative syntax I could use?

Steven

Use JmesPath (http://jmespath.org/) instead:

jmesPath(“foo[?((a==‘x’ || a==‘y’ || a==‘z’) && b==1)]”) (beware of the backticks for numbers)

Thanks I’ll take a look at JmesPath!