Testing the response of multiple JSON strings

I am trying to do a test in Postman to check the contents in a JSON response. If I just try to check one line from the JSON response, everything will be fine. My problem starts when I need to check multiple lines of a JSON response. Always fails. Any suggestion?

tests["Body matches string"] = responseBody.has("\"name\": null,
                \"nameType\": \"NON_REFUNDABLE\"");
+4
source share
1 answer

If I understand your question correctly, I would suggest you take a different approach.

Instead of looking at the entire body of the response and seeing if the lines match, you can alternatively check the individual Json properties that make up the response body. For example, you can do the following:

var data = JSON.parse(responseBody);

tests["name is null"] = data.name === null;
tests["nameType is non-refundable"] = data.nameType === "NON_REFUNDABLE";

, , . examples.

+2

All Articles