Home > database >  While extracting data from JsonPath object getting a null
While extracting data from JsonPath object getting a null

Time:12-22

While extracting data from JsonPath object getting a null,below is the json response data

{
    "status": "OK",
    "header": {
        "headerAttributes": {}
    },
    "errors": [],
    "payload": {
        "totalCount": 0,
        "returnTerms": []
    }
}

java method for extracting value from "totalCount"

public void getjsonValue() {
        JsonPath jsonPathEvaluator = response.jsonPath();
        System.out.println(jsonPathEvaluator.get("$['payload']['totalCount']"));
}

CodePudding user response:

I hope this is the last time I answer the question about JsonPath of rest-assured. People often get confused JsonPath rest-assured with JsonPath jayway, then use wrong syntax.

The right syntax is:

jsonPathEvaluator.get("payload.totalCount")

CodePudding user response:

System.out.println(jsonPathEvaluator.get("payload.totalCount").toString());

  • Related