How to use the XML to JSON Converter
- Paste your XML into the left box, or open a file.
- Adjust the options if you need to.
- Copy the JSON or download it as a file.
What does this tool do?
The XML is parsed by your browser's built-in XML parser, which also validates that it's well-formed. Attributes are kept as @name keys, text alongside child elements as #text, and repeated child elements become arrays.
How the XML is read and what the JSON keeps
Your browser's built-in XML parser reads the document, so malformed XML (an unclosed tag, a stray ampersand, two root elements) is reported with the parser's own message instead of producing partial output. The result is wrapped under the root element's name.
Attributes become keys with an @ prefix. If an element has attributes or children and also contains text, that text is stored under #text. An element with only text becomes a plain string, and an empty element becomes an empty string.
When the same child tag appears more than once, the values are collected into an array in document order. Tag names are kept exactly as written, including any namespace prefix such as dc:title.
Related: JSON to XML converter · XML formatter · JSON formatter
Things XML can say that JSON cannot
All values come out as strings, because XML does not mark a value as a number or a boolean. "12.5" stays text until your code converts it.
A list with a single entry is indistinguishable from a single value, so one <item> gives a string while two give an array. If your code expects an array, wrap single values yourself. Comments and processing instructions are not carried over.
Why use it?
- Work with XML APIs and feeds in JavaScript.
- Inspect RSS, sitemaps and SVG metadata.
- Clear error messages for broken XML.
Worked example: attributes, repeated elements and text
Given <order id="1001"><customer>Ana</customer><item>Pen</item><item>Ink</item></order>, the result is {"order": {"@id": "1001", "customer": "Ana", "item": ["Pen", "Ink"]}}. The attribute kept an @ prefix, and the repeated <item> element turned into an array.
| XML | JSON result |
|---|---|
| id="1001" attribute | "@id": "1001" |
| <customer>Ana</customer> | "customer": "Ana" |
| two <item> elements | "item": ["Pen", "Ink"] |
| one <item> element | "item": "Pen" (a single value, not an array) |
Privacy
Everything you type is processed in your browser. Nothing you enter is sent to our servers or stored by us. There's no account to create and nothing to install.
Frequently asked questions
How are XML attributes shown in the JSON?
Attributes become keys starting with @, so <item id="5"> turns into an “@id” key. Text that sits alongside child elements is kept under “#text”.
Why is an element sometimes an array and sometimes an object?
Repeated child elements become an array, but a single child stays an object. If your code expects an array, handle the single-item case — this is a common surprise with any XML-to-JSON conversion.
Content last updated . See how M2Toolkit works.