0

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']"));
}
2
  • try System.out.println(jsonPathEvaluator.get("${['payload']['totalCount']}")); Commented Dec 21, 2021 at 16:57
  • It didn't worked getting an java.lang.IllegalArgumentException: Commented Dec 21, 2021 at 17:02

1 Answer 1

6

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")
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.