What is XML to JSON Converter?
A XML to JSON Converter converts XML into JSON directly in your browser. It parses the source format, applies the standard mapping or formula, and outputs the target format ready to copy. Developers use it when debugging APIs and preparing data files.
XML to JSON Converter
Convert XML documents to JSON in your browser. Pretty-printed output.
TLDR
Paste XML, click Convert. The tool uses the browser's built-in DOMParser to parse and a small walker to emit JSON. Attributes are namespaced under '@attributes'.
About the XML to JSON converter
This tool turns an XML document into equivalent JSON. XML and JSON are the two most common data-interchange formats: XML grew out of document markup in the late 1990s and is still everywhere in SOAP web services, RSS feeds, Office documents, and enterprise configuration, while JSON is the lighter, JavaScript-native format that dominates modern REST and GraphQL APIs. Converting between them is a daily task when you are bridging an old XML feed to a JSON front end, debugging an API that speaks one format while your code expects the other, or just trying to read a dense XML payload more comfortably.
Everything runs locally using the browser's native DOMParser, so your XML never leaves the page. There is no upload, no server, and no logging, which makes it safe to paste configuration or payloads that contain private data. Paste your XML, click Convert, and copy the pretty-printed JSON.
How the conversion works
The converter parses the XML into a DOM tree, then walks that tree and builds a plain JavaScript object, which is serialised with JSON.stringify and two-space indentation. Three rules cover the structural mismatch between the formats:
element with attributes -> "@attributes": { name: value, ... }
repeated child tag -> array of objects
text-only element -> string value
- Attributes move into an
@attributesobject so they stay separate from child elements, because JSON has no attribute concept. - Repeated tags with the same name become a JSON array, preserving multiplicity that JSON keys alone cannot express.
- Leaf nodes with only text collapse to a string; mixed content (text plus child elements) keeps the text under a
#textkey.
Worked example
Take this small XML document with attributes and a repeated tag:
<root> <user id="1"><name>Alice</name></user> <user id="2"><name>Bob</name></user> </root>
Because user appears twice, it becomes an array, and each id attribute lands under @attributes:
{
"root": {
"user": [
{ "@attributes": { "id": "1" }, "name": "Alice" },
{ "@attributes": { "id": "2" }, "name": "Bob" }
]
}
}
A single user element would instead produce an object rather than an array, which is the one asymmetry to watch for when consuming the output.
XML vs JSON: what maps and what does not
| XML feature | JSON result |
|---|---|
| Element with text | String value |
| Attribute | Key inside @attributes |
| Repeated tag | Array |
| Comment | Dropped |
| Namespace prefix | Kept as part of the key, not resolved |
Common mistakes and pitfalls
- Expecting a single child to be an array. One occurrence of a tag becomes an object; two or more become an array. Code that always treats it as an array will break on single-element documents.
- Assuming comments and processing instructions survive. JSON has no equivalent, so XML comments and PIs are dropped during conversion.
- Forgetting namespaces are not resolved. A prefixed tag keeps its prefix in the key but the namespace URI is not expanded, so two different namespaces using the same prefix would collide.
- Pasting malformed XML. An unclosed or mismatched tag triggers a parse error rather than partial output. Fix the XML first.
- Relying on a perfect round trip. Converting XML to JSON and back will not reproduce attributes versus elements, comments, or original ordering across different tag names.
- Mixed content surprises. An element holding both text and child tags stores the text under #text, which is easy to miss when reading the JSON.
Frequently asked questions
How are XML attributes represented in the JSON output?
Attributes are collected into an @attributes object on the element. For example, <user id="1"> becomes {"user": {"@attributes": {"id": "1"}}}. This keeps attributes separate from child elements so nothing is lost, since JSON has no native concept of attributes the way XML does.
How are repeated XML tags converted to JSON?
When the same tag name appears more than once inside a parent, the converter turns it into a JSON array. A single <user> becomes an object, but two or more <user> elements become an array of objects. This is the standard way to preserve order and multiplicity that XML allows but JSON keys do not.
Why can XML not always round-trip back to identical XML through JSON?
XML and JSON are not perfectly equivalent. XML distinguishes attributes from elements, allows comments, processing instructions, namespaces, and mixed content, and preserves element order across different tag names. JSON has none of those, so converting XML to JSON and back can lose comments, namespace prefixes, and the distinction between an attribute and a child element.
Does the converter validate my XML?
It checks that the XML is well formed using the browser's built-in DOMParser, and shows a parse error if a tag is unclosed or mismatched. It does not validate against a schema or DTD, so it will not tell you whether the document follows a particular structure, only whether it is syntactically valid XML.
Is my XML sent to a server?
No. The conversion runs entirely in your browser using the native DOMParser and JSON.stringify. Your XML is never uploaded, logged, or stored, and the page works offline after it first loads. That makes it safe for config files or payloads containing private data.
