Q7 of 37 · API testing
What is JSON and how does it differ from XML?
Short answer
Short answer: JSON is a lightweight data format using nested key-value pairs and arrays — the de-facto standard for modern web APIs. XML is a markup format with tags, attributes, and namespaces — verbose, schema-rich, and still common in enterprise/SOAP integrations. JSON is concise; XML is more expressive at the cost of weight.
Detail
JSON (JavaScript Object Notation) is what 95% of modern APIs return:
{
"id": 42,
"email": "alice@example.com",
"roles": ["admin", "viewer"],
"active": true,
"created_at": "2026-05-10T12:34:56Z"
}
It's compact, maps cleanly to data structures in every language, and is fast to parse.
XML (eXtensible Markup Language) is the older alternative:
<user>
<id>42</id>
<email>alice@example.com</email>
<roles>
<role>admin</role>
<role>viewer</role>
</roles>
<active>true</active>
</user>
Differences that matter for testing:
| JSON | XML | |
|---|---|---|
| Syntax | brace-and-comma | open/close tags |
| Verbosity | low | high |
| Attributes | no concept | yes (<user id="42">) |
| Comments | no | yes |
| Arrays | native ([...]) |
repeated tags |
| Schema | JSON Schema | XSD (richer) |
| Path query | JSONPath | XPath (much richer) |
| Namespaces | no | yes |
Where you'll still encounter XML:
- SOAP web services (banking, telco, government).
- Enterprise integrations (SAP, Salesforce SOAP endpoints).
- Configuration / build files (Maven
pom.xml, Spring config). - RSS / Atom feeds.
Testing implications:
- JSON parsing is built into nearly every test framework. Tools like JsonPath / Jq let you assert on nested fields.
- XML testing involves namespaces, XSD validation, XPath queries — heavier but more rigorous.
- Schema validation: JSON Schema for JSON; XSD for XML. XSD is strictly more expressive (data types, regex constraints out of the box, namespaces).
For interviews: know both syntaxes, recognise XML in legacy contexts, and articulate why JSON won — speed, simplicity, JS-native — while acknowledging XML's strengths in heavyweight enterprise scenarios.