0

I have the following JSON payload:

{
    "inputs" : [{
            "attributeX" : [{
                    "id1" : "value11",
                }, {
                    "id1" : "value12",
                }
            ],
            "attributeY" : [{
                    "id" : "valueY1",
                    "attributeZ" : [{
                            "pathZ" : "/Path1/Path2[00163E038C2E1EE299C1C394370BCFA0]/Description",
                            "value" : "valueXYZ",
                        }
                    ],
                }
            ]
        }
    ]
}

I would like to write a JSON path expression so that I want to get the value of pathZ. However part of the value within the [] is dynamic. Is there anyway of specifying a wild card within the following JSON path expression ?

$.inputs.[*].attributeY.[*].attributeZ[?(@.pathZ=='/Path1/Path2**<HOW_CAN_I_SPECIFY_A_WILDCARD_HERE>**/Description')].value

1 Answer 1

1

You can use a regex in the JSON Path expression to match the start and end of the PathZ value, without matching the middle. This is what the expression would look like:

$.inputs.[*].attributeY.[*].attributeZ[?(new RegExp('^/Path1/Path2.*/Description$').test(@.pathZ))].value

I have tested this using the online JSON query tool here: http://www.jsonquerytool.com/sample/jsonpathregex

Sign up to request clarification or add additional context in comments.

Comments

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.