We can parse a JSON response and get a particular field from Response in Rest Assured. This is done with the help of the JSONPath class. To parse a JSON response, we have to first convert the response into a string.
To obtain the response we need to use the methods - Response.body or Response.getBody. Both these methods are a part of the Response interface.
Once a Response is obtained it is converted to string with the help of the asString method. This method is a part of the ResponseBody interface. Then we shall obtain the JSON representation from the response body with the help of thejsonPath method.
We shall first send a GET request via Postman on a mock API URL and go through the response.
Using Rest Assured, we shall get the values of the Course, id and Price fields.