jayway jsonpath expression finding value within a collection of strings

47 views Asked by At

Having difficulty building up a filter expression using jayway jsonpath for my Java application and looking to know if the following is possible?

Is it possible to write an expression that would find all objects in an array where test.Value contains "val" and test2.Value contains "val".

I've tried regex filter expression like so but returns all results when the filter should return nothing:

$..[?(@.test.Value[?(@ =~ /.*invalid/i)])]

[
   {
        "test": {
            "Value": [
                "value1",
                "value2"
            ],
        },
        "test2": {
            "Value": [
                "value3",
                "value4"
            ],
        },
   }
   ...
]

Would be great if I could do this within one expression.

UPDATE:

Solved it! For anyone interested, I didn't see the filter operator empty. Specifying if empty is false or true allows the filter to return a boolean and not a list! Lesson learned.

$..[?(@.test.Value[?(@ =~ /.*invalid/i)] empty false)] = [] or empty result

$..[?(@.test.Value[?(@ =~ /.*ue1/i)] empty false)] = match!

0

There are 0 answers