My JSON (simplified) looks like this:
[
{"name" : "foobar",
"id" : 123
},
{"name" : "bar",
"id" : 123
},
{"name" : "foobar",
"id" : 456
}, ...
]
I'm using https://jsonpath.herokuapp.com/ to try and find the right JSONPATH syntax to filter out anything not starting with foo
, and having id == 123.
Getting it to filter the ones that do start with foo
is easy:
$..[?(@.name =~ /foo.*/i)]
This yields the following results:
[
{
"name" : "foobar",
"id" : 123
},
{
"name" : "foobar",
"id" : 456
}
]
I can get rid of the id 456 by adding an additional filter like so:
$..[?(@.name =~ /foo.*/i && @.id==123)]
But how do I do the opposite of getting the name starting with foo
? I want all entities that do not start with foo
.
I tried something like this:
$..[?(!@.name =~ /foo.*/i && @.id==123)]
Which at least parses as valid JSONPATH, and should negate the filter, but for some reason it still happily only reports the foobar
entry:
[
{
"name" : "foobar",
"id" : 123
}
]
How can I achieve a NOT LIKE
in JSONPATH?
Thanks!