JSON vs XML: Why Modern APIs Almost Always Choose JSON
2024-06-25
SOAP and XML dominated enterprise integration years ago; today public API docs are overwhelmingly JSON. Here is why—and when XML still makes sense.
Syntax and readability
JSON is minimal: objects, arrays, scalars—no closing tags or namespaces for typical API payloads.
XML shines for document models with mixed content and attributes; JSON is simpler for field bags.
{ "id": 1001, "name": "Alice", "roles": ["admin"] }<user><id>1001</id><name>Alice</name><roles><role>admin</role></roles></user>Payload size
Tag overhead makes XML larger for the same data; compression helps but bytes still matter on mobile.
Parsing and DX
Native JSON.parse in browsers and Node; XML needs extra parsers and XPath mental overhead.
Schemas and tooling
XSD vs JSON Schema—both work, but OpenAPI examples and TS/Go/Python models assume JSON.
When XML still fits
Legacy SOAP, regulated industries, document standards (OOXML, SVG). Greenfield web APIs: JSON by default.
Migration tips
New endpoints in JSON; gate old XML behind adapters with a deprecation timeline. Validate payloads while migrating.