XML to JSON Converter
Paste an XML document and get readable JSON. Keep or drop attributes, and switch the mode to convert JSON back to XML.
0 characters
0 characters
Processed locallyFiles and text are processed in your browser and are not uploaded to our servers.Learn more
How to convert XML to JSON
- 01
Paste your XML
A complete document with a single root element.
- 02
Choose attributes
Keep attributes is on by default. Turn it off to convert only elements and text.
- 03
Convert and copy
Copy the JSON or download it.
How XML is mapped to JSON
- The root element becomes the single top-level key.
- An element that contains only text becomes a string; an empty element becomes an empty string.
- Sibling elements with the same name become an array. A name that appears once stays a single value.
- Attributes are collected in an "@attributes" object.
- Text next to child elements is stored under "#text". The order of text and child elements relative to each other is not preserved.
- Namespace prefixes such as soap:Envelope are kept in the names. Comments and processing instructions are left out.
Limits and safety
The XML is parsed by your browser's own XML parser. Documents with a DOCTYPE or entity declarations are refused, which also rules out entity-expansion attacks. Very large documents, over 8 MiB of text or more than 256 levels deep, are refused rather than freezing the page.
All values stay strings: the converter does not guess whether 007 is a number.
Related tools
Frequently asked questions
How are repeated XML elements converted?
Elements with the same name under one parent become a JSON array. If an element appears only once, it is a single value, so check for both shapes when you process the JSON.
What happens to XML attributes?
With Keep attributes on, they appear in an "@attributes" object on the element. Turn it off to leave them out.
Can I convert JSON to XML?
Yes. Switch Mode to JSON to XML. The JSON needs one root key, and "@attributes" and "#text" are turned back into attributes and text.
Why is my XML rejected?
Common causes are unclosed tags, more than one root element, or a DOCTYPE declaration, which is not supported.