Checking JSON and XML Responses
Working with JSON Responses
JSON is the most common API response format. Postman automatically pretty-prints JSON in the response viewer, and pm.response.json() lets scripts parse it directly into a usable object for assertions.
Working with XML Responses
For APIs that return XML, Postman's response viewer can render it in a readable tree format. In scripts, xml2Json() can convert the XML body into a JSON-like object so it can be validated the same way.
Choosing the Right Checks
| Format | Parsing Method | Common Check |
|---|---|---|
| JSON | pm.response.json() | Field values, structure |
| XML | xml2Json(pm.response.text()) | Element/attribute values |
Content-Type Awareness
Checking the Content-Type header before parsing helps a test script handle both formats gracefully, especially when an API can return either one.
Ready to master Postman API Testing Course?
Join Uncodemy's hands-on training and build real-world API testing skills with expert mentors.