XML to JSON Converter
Convert XML to JSON with attributes, arrays, CDATA and namespaces handled your way. Paste or upload .xml files, pretty or compact output.
Loading XML to JSON Converter…
Your files never leave your device
About this tool
XML is still everywhere: SOAP APIs, RSS and Atom feeds, Office files, sitemaps and legacy exports. Modern apps and JavaScript code prefer JSON. This XML to JSON converter parses your XML and turns it into JSON objects and arrays, with clear choices for the parts of XML that have no direct JSON equivalent, such as attributes, repeated elements and namespaces.
How to convert XML to JSON
- Paste XML or upload a .xml file.
- Choose how attributes, arrays and text are represented.
- Set indentation, or compact output.
- Copy or download the JSON.
Example
<book id="bk101"><title>Midnight Rain</title><price>5.95</price></book>
becomes
{"book":{"@id":"bk101","title":"Midnight Rain","price":5.95}}
Options
- Include attributes with a prefix such as @ so they do not clash with child elements, or drop them if you do not need them.
- Array mode: automatic (repeated elements become arrays), always use arrays, or compact single items.
- Text node name (#text) for elements with both attributes and text.
- CDATA preservation with its own node name.
- Ignore namespaces for simpler keys, or keep prefixes.
- Include comments from the XML if you need them.
- Parse numbers and booleans into real JSON types, or keep every value as text.
- Indentation of 2, 4 or 8 spaces.
Why the arrays setting matters
In XML, one <item> and three <item> elements look alike, but in JSON one becomes an object and three become an array. Code that expects an array then breaks on the single item. If your app always expects lists, choose always use arrays for predictable output.
Tips
- Turn off number parsing for codes with leading zeros, such as 00123, so they stay text.
- Check that the XML is well formed: every tag closed, one root element, attributes quoted.
- Large feeds convert fine in the browser; the statistics show elements and depth.
Frequently asked questions
How are XML attributes converted?
With Include attributes on, they become keys with a prefix such as @id, next to the child elements. You can also choose to drop attributes.
Why is one element an object and another an array?
In automatic mode, repeated elements become arrays and single elements become objects. Choose Always use arrays for consistent output.
What happens to namespaces?
You can keep namespace prefixes in the keys or ignore namespaces for simpler JSON.
Are numbers converted to JSON numbers?
Yes, with Parse numbers on, which is the default. Turn it off to keep every value as text, for example for IDs with leading zeros.
Can I upload an XML file?
Yes. Upload a .xml or .txt file or paste the XML directly.
Is my file uploaded to a server?
No. Parsing and conversion happen in your browser.
