javajsonjsonpathjayway

How to extract array element without key?


I have a json as below. I want a json path expression that checks if [e3] exists in the below json. Can someone help please?

{
    "status": "ok",
    "error": [
        "[e1]",
        "[e2]",
        "[e3]",
        "[e4]"
    ]
}

Solution

  • The below JSONPath will return a list with one element. Indefinite paths always returns a list. A path is indefinite if it contains an expression - ?(<expression>). Refer What is Returned When?

    $.error[?(@ == '[e3]')]
    

    Jayway JsonPath