XML to JSON Converter
Turn XML into predictable JSON, with attributes and repeats handled well.
How to use the XML to JSON Converter
- Paste XML on the left, or open or drop an .xml file. The document is checked for well-formedness first.
- Read the JSON on the right. Each element becomes a key, attributes get a prefix, and text that shares an element with them sits under "#text".
- Decide whether attributes are kept, whether numbers and booleans are typed, and whether repeated tags are always lists.
- Copy the JSON or save it as data.json.
Examples
About this tool
XML and JSON model data differently, so every converter has to make choices: XML has attributes, mixed text and tags that repeat, while JSON has only objects, arrays and plain values. This tool makes those choices explicit. Elements become object keys, attributes become keys with a prefix such as @id, text that sits beside attributes or child elements is stored under "#text", and an empty element becomes an empty string.
Repeated tags are the classic trap. A naive conversion turns two <item> tags into an array but a single <item> into an object, so code that reads the result breaks on the first short document. With "Always use arrays for repeated tags" switched on, every tag that appears more than once anywhere in the document is written as a list wherever it appears, giving consumers one predictable shape. Type conversion is deliberately careful too: 42 and 3.5 become numbers and true and false become booleans, but 007, phone numbers and 20-digit identifiers stay strings.
Before anything is converted the document is checked: an unclosed tag, a bare & or a second root element is reported with its line and column rather than producing half a result. Comments, processing instructions and the XML declaration are not data and are left out. Tip: the JSON Tree Viewer on this site is a comfortable way to explore a large result.
Frequently asked questions
How are attributes represented?
As keys on the same object as the child elements, marked with a prefix so they cannot be confused with tags: <price currency="EUR">4.50</price> becomes {"@currency": "EUR", "#text": 4.5}. You can switch the prefix to _ or @_ under More options, or drop attributes entirely.
Why is a single tag sometimes wrapped in an array?
Because the same tag appears several times somewhere else in the document. The converter looks at the whole file and uses a list for that tag everywhere, so a shelf with one book and a shelf with three books get the same structure. Turn the option off if you prefer the literal shape of each element.
What happens to mixed content like <p>Hello <b>world</b></p>?
The child element becomes its own key and the surrounding text pieces are joined under "#text", so their exact position between the children is lost. JSON has no good representation for mixed content; if you need it preserved, keep that part as XML text inside a CDATA section.
Is my XML uploaded?
No. Validation and conversion both run as JavaScript in this page, and the file is never sent anywhere. Exports from accounting systems, SOAP responses and customer feeds stay on your computer.
Are entities and CDATA decoded?
Yes. &, <, numeric references such as © and common HTML names like are turned into the characters they stand for, and the content of a CDATA section is taken literally and merged with the surrounding text. Entities declared in a DOCTYPE inside the file are expanded as well.