javajsonjsonpathjson-path-expression

Generate JSONPath based on condition


Json

{
    "Id": "1234",
    "AValue": {
        "qId": "ABCD",
        "aType": "DATE",
        "value": {
            "eType": "ENCRYPTED",
            "eValue": "XXXXXXX"
        }
    }

}

How to write a jsonpath expression to get eValue only if "qId in AValue is ABCD"


Solution

  • We can use conditions

    $.AValue[?(@.qId =="ABCD")].value.eValue