XML Tools
XML to JSON
Convert an XML document into readable JSON while keeping the root name, attributes, repeated child elements, and the order of mixed text. Text values remain strings.
✓ Every tool runs in your browser. We do not upload your input or output.
Keyboard shortcuts
Ctrl/⌘ + Enter: process
Ctrl/⌘ + Shift + F: full screen
Esc: exit full screen
Ctrl/⌘ + F in editor: search
How to use
- Paste or upload a well-formed XML document, or load the sample orders.
- Process the input and review the JSON object named after the XML root element.
- Check @-prefixed attributes, arrays for repeated children, and #content for text mixed with elements.
- Copy the JSON or download it as a .json file for further processing.
Examples
Keep an order ID attribute
The attribute becomes @id, while element text stays a string so 24.50 is not silently changed to a number.
<order id="A-101"><customer>Avery</customer><total>24.50</total></order>
{"order":{"@id":"A-101","customer":"Avery","total":"24.50"}}Represent mixed text
The #content array keeps the sequence of text and child elements.
<p>Hello <strong>world</strong>!</p>
{"p":{"#content":["Hello ",{"strong":"world"},"!"]}}A predictable XML-to-JSON mapping
XML and JSON model documents differently. XML has attributes, ordered child elements, and text between elements; JSON has objects and arrays. This converter uses explicit keys so those differences are visible. The JSON object’s outer key is the XML root name. An attribute such as id="A-101" becomes "@id": "A-101". Child elements become properties, and repeated siblings become arrays.
Leaf text remains a string. That choice protects identifiers with leading zeros and values such as 24.50 from unwanted type conversion. An empty element becomes an empty string unless it has attributes. Text in an element that also has attributes appears under #text.
Mixed content and limits
A paragraph can contain text before and after an inline element. The converter writes that sequence to #content, for example text, then a child object, then more text. This preserves reading order in JSON. Comments and processing instructions are intentionally omitted from the converted data; use XML Viewer or Formatter if you need to inspect or retain them.
The input is checked for XML well-formedness and namespace errors before conversion. DOCTYPE declarations are not supported, and no external data is fetched. Parsing and conversion run locally in your browser’s Web Worker. Large input stays inside the workspace panels, and Copy and Download use the complete JSON result.
Frequently asked questions
How are XML attributes represented?
Each attribute becomes a key beginning with @, such as @id. This keeps it distinct from an element with the same name.
What happens to repeated elements?
Siblings with the same name become an array. A single child with that name remains one value.
Are numbers and booleans inferred?
No. XML text has no built-in JSON type, so values such as 0012, true, and 24.50 remain strings.
Can I convert the JSON back to identical XML?
Not generally. Comments, processing instructions, CDATA boundaries, and some formatting details are not represented in the JSON mapping.
What if the XML contains mixed text and child elements?
A #content array preserves their order. This is useful for paragraph-like XML, but downstream code needs to understand that convention.