1

I am trying to filter a list of formParagraph objects where the hasContent property is true and the legalStatutes string array contains a string with 'AIA'. issue is that 'AIA' is not always in zero position in the array.

The below JSONPath only works if 'AIA' is first item in array.

   $.businessResponse.formParagraphList[ ? ((@.hasContent == true) && (@.legalStatutes[0] == 'AIA'))] {
    "rbacUser": null,
    "businessResponse": {
        "formParagraphList": [{
                "id": 1261,
                "hasContent": true,
                "legalStatutes": [
                    "Pre_AIA",
                    "AIA"
                ]
            },
            {
                "id": 67,
                "hasContent": true,
                "legalStatutes": [
                    "AIA",
                    "Pre_AIA"
                ]
            },
            {
                "id": 68,
                "hasContent": true,
                "legalStatutes": [
                    "Pre_AIA"
                ]
            }
        ]
    }
}

Is there a way to check for the existence of a specific string in a string array within a JSON object without knowing it's index using JSONPath?

1 Answer 1

2

Ok, figured out a solution to my problem. Used the .indexOf() method to check if the string exists in the array.

$.businessResponse.formParagraphList[?((@.hasContent==true) && (@.legalStatutes.indexOf('AIA') > -1))]

UPDATE: The above JSONPath is valid in online evaluators, but it didn't work in Newtonsoft for C#. here is what I got to work with this library.

$.businessResponse.formParagraphList[?(@.hasExaminerNote==true && @.legalStatutes[*]=='Pre_AIA')]
Sign up to request clarification or add additional context in comments.

1 Comment

One note, this doesn't work using newtonsoft in c#. will post that answer when I find it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.