A brief history
XML (Extensible Markup Language) was standardized by the W3C in 1998, designed as a more flexible replacement for SGML and a complement to HTML. Through the early 2000s, XML became the dominant format for everything: web services ran on SOAP (XML over HTTP), configuration files used XML (web.config, pom.xml, AndroidManifest.xml), and data interchange between enterprise systems relied on XML schemas. The era produced a sprawling ecosystem of standards: XSLT, XPath, XQuery, XML Schema, DTD, WSDL, and many more.
JSON (JavaScript Object Notation) was formalized by Douglas Crockford in the early 2000s as a simpler alternative. It borrowed syntax from JavaScript object literals, making it natively parseable in browsers without a library. REST APIs — which gained popularity over SOAP largely because of their simplicity — naturally adopted JSON. By 2010 JSON had overtaken XML as the default for new web APIs, and today the gap is enormous: nearly all public REST APIs use JSON.
The core differences
The most obvious difference is verbosity. Here's the same data in both formats:
<!-- XML -->
<user>
<id>42</id>
<name>Alice</name>
<email>alice@example.com</email>
<roles>
<role>admin</role>
<role>editor</role>
</roles>
</user>
// JSON
{
"id": 42,
"name": "Alice",
"email": "alice@example.com",
"roles": ["admin", "editor"]
}The JSON version is roughly half the size and arguably easier to read. This size difference matters at scale: a REST API returning thousands of records per second saves meaningful bandwidth with JSON. Native browser support matters too: JSON.parse() is a built-in JavaScript function, while XML requires the DOMParser API or a third-party library.
What JSON does well
- Web API responses.JSON is the universal language of REST APIs. Every HTTP client library in every language has first-class JSON support. There's zero friction going from a JSON API response to a typed object in your code.
- Configuration files.JSON (or its variants like JSON5 and JSONC) is widely used for configuration: package.json, tsconfig.json, .eslintrc, VS Code settings. It's more structured than YAML (no ambiguous indentation) and more widely supported than TOML.
- NoSQL databases. MongoDB, Firestore, DynamoDB, and Couchbase all use JSON-like document storage. Working with these databases in your application is seamless when your API already uses JSON.
- Compact representation.JSON's lack of end tags and attribute syntax makes it consistently more compact than equivalent XML. For high-throughput APIs, this reduces bandwidth and parsing time.
What XML does better
- Mixed content. XML supports nodes that contain both text and child elements — essential for document formats like DOCX, HTML, and SVG. JSON has no equivalent: a value is either a string or an object, never both inline.
- Namespaces. XML namespaces allow schemas from different organizations to be merged in a single document without key conflicts. This is why SOAP, WSDL, and enterprise middleware rely on XML.
- Formal schema validation. XML Schema Definition (XSD) provides extremely precise constraints: specific string patterns, numeric ranges, required vs optional elements, and complex conditional constraints. JSON Schema is capable but less mature and not universally supported.
- XSLT transformation. XSLT lets you transform one XML document into another format — another XML document, HTML, plain text — using a declarative stylesheet. This is extensively used in publishing, document processing pipelines, and data integration.
- Comments. XML supports comments naturally. JSON does not — comments are explicitly excluded from the spec. For configuration files where you want to explain settings, this is a real limitation (hence JSON5 and JSONC variants that add comment support).
When the choice is made for you
In many practical situations, you don't choose the format — it's dictated by the existing ecosystem. Enterprise middleware, healthcare data exchange (HL7 FHIR uses JSON but older HL7 v2/v3 uses XML), government services, and legacy SOAP integrations are XML by default. SVG (vector graphics) is XML. Microsoft Office formats (DOCX, XLSX, PPTX) are XML inside a ZIP. RSS and Atom feeds are XML. If you're integrating with any of these, you're using XML.
For new projects under your control, default to JSON unless you specifically need one of XML's features: mixed content, namespaces, XSLT, or formal XSD validation. JSON's simplicity and universal support make it the right default for modern applications.
The bottom line
JSON for APIs, configuration, and application data. XML for document formats, enterprise integration, publishing pipelines, and wherever the ecosystem already uses it. In most greenfield projects you'll use JSON exclusively; in enterprise environments you'll use both and need to know how to convert between them. Tools like JXON, xml2js (Node.js), and Python's xmltodict make conversion straightforward.
Related tools
JSON Formatter & Validator →