In the early 2000s, if you wanted two systems to talk to each other, XML was the answer. Today, JSON is the default for almost every web API. How did that happen, and does XML still have a place?
Why JSON won
JSON's biggest advantage is that it maps directly onto the data structures programming languages already use. An object is a dictionary, an array is a list, a string is a string. When your API client is JavaScript running in a browser, JSON isn't just convenient, it's native: JSON.parse() and JSON.stringify() are built in.
It's also much lighter. Compare a typical XML document with its JSON equivalent and the JSON version is often half the size, because there are no opening and closing tags repeated for every field. That means less bandwidth, faster parsing, and happier mobile users.
And it's genuinely human-readable in a way XML struggles to match. Compact JSON is still easy to skim; the equivalent XML is dominated by tag noise.
Where XML still matters
None of this means XML is dead. It remains the foundation of several ecosystems:
- SVG is XML, so every icon you ship is technically XML.
- SOAP-based enterprise APIs are still running inside banks, airlines, and government systems.
- Office document formats (DOCX, XLSX) are zipped XML files.
-
Configuration files like Maven's
pom.xmlor Android layouts lean on XML's strictness.
XML's real strength is namespaces, schemas (XSD), and mixed content, where text is interleaved with child elements. JSON has no direct answer for those. If your document needs attributes and structured validation, XML is a legitimate choice.
The practical takeaway
For new APIs, choose JSON. It's simpler, faster, and the whole ecosystem, from OpenAPI to JSON Schema to every language's standard library, has converged on it. For documents with complex validation or long-term archival, XML still earns its keep.
One habit that saves me time daily: after generating API responses, I run them through a formatter to catch syntax errors before debugging code that isn't the problem. JSON Formatter is my go-to, it validates, pretty-prints, and works entirely in the browser, so nothing sensitive ever leaves my machine.
Top comments (0)