Jay Jay - 1 month ago 15
Java Question

Rest-assured. Is it possible to extract value from request json?

I'm getting response this way:

Response response = expect().statusCode(200).given().body(requestBody).contentType("application/json")
.when().post("/admin");
String responseBody = response.getBody().asString();


I have a json in responseBody:

{"user_id":39}


Could I extract to string using rest-assured's method only this value = 39?

Jay Jay
Answer

I found the answer :)

Use JsonPath or XmlPath (in case you have XML) to get data from the response body.

In my case:

JsonPath jsonPath = new JsonPath(responseBody);
int user_id = jsonPath.getInt("user_id");