Using the converter
Paste XML on the left and JSON appears on the right. Attributes keeps or drops them, and dropping them is right more often than you'd think for XML that only uses attributes for ids.
An element holding nothing but text becomes a string. An element with attributes or child elements becomes an object, where attributes are prefixed with @ and any loose text sits under #text. Two children with the same name become an array.
Broken XML is refused with the reason, such as a tag that is never closed or a bare < in the text. Nothing is quietly dropped.
There is no correct mapping
XML and JSON disagree about what a document is. XML has attributes and JSON doesn't. Text and elements can sit side by side inside one XML tag, with no way to hold that in JSON. Then there are namespaces, comments and processing instructions, none of which JSON has.
So every XML-to-JSON converter invents a convention, and there are at least half a dozen named ones: Badgerfish, Parker, GData, Spark and more. They disagree about attribute prefixes, about whether a single child should be an array, and about what to do with mixed content.
This page uses the @ and #text convention because it loses the least and reads the clearest. The important thing is knowing which one you have, since JSON produced under one set of rules won't go back through another.
Why XML got smaller and JSON got bigger
XML 1.0 became a W3C Recommendation in February 1998 and spent a decade as the default answer for everything: configuration, documents, remote calls, feeds. SOAP wrapped every message in envelopes of it.
JSON went the other way. Douglas Crockford has said he discovered rather than invented it, in 2001, since it's a subset of JavaScript that was already there. The grammar fits on one page, and there's nothing to argue about because there's nothing in it.
XML hasn't gone anywhere. It's still under RSS and Atom feeds, Office documents, SVG, Android layouts and most enterprise messaging.
Related conversions
JSON to XML is the return trip and has to invent a root element. YAML to JSON covers the format that replaced XML for configuration.
The same tag parser drives HTML to Markdown, pointed at prose instead of data.
Questions
How do I convert XML to JSON?
Paste the XML above. Attributes are kept with an @ prefix by default, and you can drop them with the Attributes control.
Why do attributes have an @ in front?
To keep them apart from child elements, which would otherwise collide. An element with an id attribute and an id child would produce one key without the prefix.
What happens to repeated elements?
The second one turns the value into an array. A single child stays a plain value, so XML with one item reads differently from XML with two.
Is there a standard for this?
No. Several named conventions exist, including Badgerfish and Parker, and they disagree. This page uses the @ and #text convention and says so, so you know what you have.
Sources
- W3C: Extensible Markup Language (XML) 1.0 (W3C Recommendation 10 February 1998)
- Wikipedia: JSON
- Douglas Crockford: The JSON Saga (talk transcript)
- Open311: JSON and XML Conversion
Added . Last updated and reviewed . What's new






