XML was the data format of the 2000s; JSON is the format of the web era. But legacy APIs, config files, and documents still speak XML — so conversion between the two remains a regular chore.
What they share, what they don’t
Both represent structured data as text. The differences:
- Syntax: XML wraps values in open/close tags (
<name>Ada</name>); JSON uses braces and colons ("name": "Ada"). - Attributes: XML has them (
<user id="42">); JSON doesn’t — attributes become keys like"@id"or"id"in conversion. - Brevity: JSON is typically 30–50% smaller for the same data. XML’s closing tags are pure overhead.
Converting
- Paste your XML into the XML ↔ JSON converter.
- Get the JSON equivalent instantly — conversion happens locally in your browser.
- Tidy the result with the JSON formatter to read the structure at a glance.
The conversion wrinkles
- Attributes become keys:
<user id="42">turns into something like"@id": "42"or"id": "42"depending on the converter’s convention. Check the output before relying on it. - Arrays vs single items: XML has no concept of “a list of one.” A single
<item>converts to an object, two<item>s to an array — the inconsistency breaks code that expects one shape. Most converters have an option to force arrays; if yours doesn’t, handle both cases in your code. - Mixed content: XML that interleaves text and tags (
<p>Hello <b>world</b></p>) doesn’t map cleanly. If your XML does this, it’s a document, not data — conversion will lose the structure.
For modern APIs, JSON wins by default. XML remains the answer for legacy systems, government interfaces, and formats like SVG and RSS — and when they meet, a converter bridges the gap.