About the XML → JSON
This XML to JSON converter parses XML in your browser and outputs indented JSON while you type. It is meant for developers, analysts and integrators who need to inspect or reuse XML data from feeds, legacy APIs or config files in a JSON-based workflow.
How it works
The tool uses the browser's built-in XML parser (DOMParser). If the parser reports an error, the message is shown with the line and column, plus a snippet of the surrounding XML. Otherwise it walks the tree from the root element, and the root's name becomes the top-level key.
Attributes become keys with the prefix you choose (@ by default). An element with only text becomes that text; text alongside attributes or child elements, including CDATA, is stored under "#text". Repeated sibling tags are collected into arrays, or every child becomes an array if you tick that option. Values stay strings unless you tick Convert numbers & booleans.
How to use
- 1
Paste your XML or open an XML file.
- 2
Choose options: include attributes and their prefix, convert numbers, always use arrays, empty elements as null.
- 3
If the XML is invalid, fix the line shown in the error.
- 4
Copy or download the JSON, with 2 or 4 space indentation or minified.
Worked examples
Repeated elements become an array
Converting a small product list.
Nested elements
A simple user record.
The root element <user> itself is not a key; its children become the top-level properties.
Frequently asked questions
Does the conversion keep XML attributes?+
Yes. Attributes become keys with a prefix, @ by default, for example id="5" becomes "@id": "5". You can change the prefix or leave attributes out.
How are repeated elements handled?+
When the same tag appears more than once under one parent, its values are collected into a JSON array. Tick Always use arrays for children to make every child an array.
Is the root element included?+
It isn't: the root element's name is the top-level key of the JSON.
Are numbers converted to JSON numbers?+
Only if you tick Convert numbers & booleans. By default all values stay strings, which avoids losing leading zeros.
Why convert XML to JSON at all?+
JSON is the native data format for JavaScript and most modern APIs, so converting makes XML data easier to inspect, store and use in current applications.