XML to JSON and back
Paste or load an XML file and get the matching JSON, or take the opposite route. If the XML is broken we tell you the line, the column and the rule that was broken.
Or drop an .xml or .json file here, or tap to pick one
How to read the conversion
An XML element becomes a JSON object. Attributes take the @ prefix, so <price currency="EUR">12.90</price> becomes {"@currency":"EUR","#text":"12.90"}. An element with only text and no attributes becomes the string itself, and an empty element becomes null. Sibling elements sharing a name become a list, and the root element stays as the single key at the top. The convention cannot collide, because the at sign and the hash are not allowed inside an XML name, so no element will ever be called #text.
The single item list trap
This is the one that bites in production. If the feed carries three <row> elements you get a list, but if the very same feed carries one you get an object, and the code looping over the list breaks on a file that looked identical. No converter can guess it from the XML alone, because cardinality lives in the schema (XSD), not in the data. That is why the box that always puts children in a list exists: turn it on when a program reads the JSON, leave it off when you want JSON that is pleasant to read.
What does not make it into the JSON
Comments and processing instructions are left out, because JSON has nowhere to keep them, and the page says so with a warning instead of dropping them silently. CDATA sections become plain text. The DOCTYPE is skipped, so entities declared in a DTD are not resolved: if one shows up the tool stops and names it. Namespace prefixes are kept literally (soap:Envelope stays soap:Envelope) without resolving URIs. Leading and trailing whitespace around an element text is trimmed.
Why the error gives a line and a column
Parsing is done by a parser written for this page, not by the browser XML reader, which reports different messages on Chrome, Firefox and Safari. That way you get the exact spot and the rule that was broken: XML attribute quotes are mandatory, tags close in the reverse order they were opened, there can be only one root element, and a lone ampersand must be written &. Those four are behind almost every rejected export.
Going back from JSON to XML, and file encodings
The other way round, keys become elements, keys with an at sign become attributes, #text becomes the text and lists become repeated elements. If a key cannot be a valid XML name (it starts with a digit, or it contains a space) the tool stops and names it instead of mangling it. Special characters are escaped in text and in attribute values alike. When you load a file that declares an encoding other than UTF-8, ISO-8859-1 for instance, the file is read again with that encoding and the result is always UTF-8. Everything runs in the browser, with nothing sent to a server.