Consider the following JSON:
{
"expensive": 10,
"abc":10
}
I would like to write a filter that returns true if the key abc
equals 10
, i.e. on the example above the answer is true
, while on the following example it is false
:
{
"expensive": 10
}
because there is no such key abc
.
I have tried these filters:
$[?(@ == 10)]
returns[10,10]
on the first json and[10]
on the second, but I want to enforce the check on theabc
field, i.e. the second should return nothing. how can this be achieved?
CodePudding user response:
I'm assuming you have an array of input objects and want to filter them.
[{
"expensive": 10,
"abc":10
}, {
"expensive": 10
}]
Here $[?(@.abc == 10)]
returns
[
{
"expensive": 10,
"abc": 10
}
]
and $[?(@.abc == 10)].expensive
returns
[
10
]