XML ↔ JSON Converter
An XML to JSON converter and JSON to XML converter that share one ordered element tree. Attribute order, namespace declarations, repeated siblings and mixed text are kept, DOCTYPE declarations are rejected and everything runs locally in your browser.
Your text never leaves your browser.
Direction
Both directions use the same ordered tree. Comments, processing instructions, the XML declaration and CDATA markers are not kept. DOCTYPE declarations are rejected.
XML → JSON
JSON output
Paste an XML document or load the sample, then press Convert.
How the XML to JSON converter maps a document
Paste one well-formed XML 1.0 document and press Convert. Every element becomes an object with the same four keys, so the output is predictable: attributes and children are ordered arrays, qualified names are kept as written, and every value stays a string. Whitespace inside elements is kept; whitespace outside the root is not. Line endings, entities and attribute values are normalized the way any XML 1.0 parser reads them.
| XML | JSON tree |
|---|---|
| Element | { "type": "element", "name", "attributes": [], "children": [] } |
| Attribute or xmlns declaration | { "name", "value" } in source order |
| Text, CDATA, entity and character references | { "type": "text", "value" }, adjacent parts combined |
| Comments, PIs, XML declaration, DOCTYPE | Not kept (DOCTYPE is rejected) |
This is a structural round trip with normalized syntax: converting the JSON back gives the same elements, attributes and text, but not necessarily the same characters as your original file. Quote style, CDATA markers, comments and indentation outside text are not reproduced.
Worked example
The sample has an attribute that looks like a number, mixed text around a child element and an entity. The JSON uses two-space indentation and no final newline. Converting it with the JSON to XML converter produces the exact XML again.
<item id="007">Hi <b>there</b> & bye</item>
{
"type": "element",
"name": "item",
"attributes": [
{
"name": "id",
"value": "007"
}
],
"children": [
{
"type": "text",
"value": "Hi "
},
{
"type": "element",
"name": "b",
"attributes": [],
"children": [
{
"type": "text",
"value": "there"
}
]
},
{
"type": "text",
"value": " & bye"
}
]
}How the JSON to XML converter writes XML
Switch to JSON → XML and paste a tree in the format above. The XML is written without a declaration, added indentation or final newline. Attributes use double quotes and empty elements self-close, as in <br/>. &, < and > are escaped everywhere, " in attributes, a carriage return in text becomes , and tab, LF and CR in attributes become 	, and . The generated document is parsed again under the same rules before you can copy it. Use result as input sends the output back to the input and switches direction.
Limits
Input and output are each limited to 512 KiB of UTF-8, elements to 48 levels of nesting including the root, and the tree to 5,000 elements, text nodes and attributes combined. Formatted JSON is several times larger than compact XML, so a JSON result can exceed the output limit while its XML source is well under the input limit. Nothing is truncated: an oversized result shows an error instead.
To pretty-print or validate the XML itself, use the XML Formatter. To format or check the JSON, use the JSON Formatter.
Frequently asked questions
What JSON does the JSON to XML converter accept?
Only the element tree this tool produces. The root is an object with exactly the keys type, name, attributes and children, where type is "element". Children are element objects or text objects with exactly type and value. Attributes are objects with exactly name and value. Every name and value is a string, and attributes and children are always arrays, even when empty. Duplicate JSON keys, unknown keys, wrong types, invalid XML names, characters XML 1.0 does not allow, duplicate attributes and invalid namespace bindings are rejected with a JSON Pointer path such as /children/0/name. Arbitrary JSON objects are not mapped to XML.
How are attributes represented?
As an ordered array of { "name", "value" } objects in source order, not as JSON object keys. Values are always strings, so id="007" stays "007". Values follow XML attribute-value normalization: literal tabs and line breaks become spaces, while character references such as are kept. When converting back, tab, LF and CR are written as 	, and so they survive another round trip.
What happens to repeated elements and mixed text?
Nothing is grouped or merged. Repeated siblings stay as separate entries in the children array, in document order, and text between elements becomes its own text node, including whitespace inside elements. Adjacent text, CDATA sections and character references are combined into one text node, and empty text nodes are dropped.
Are namespaces supported?
Yes. The XML is parsed with namespace checks, so prefixes must be declared. Qualified names such as soap:Envelope are kept exactly as written, and xmlns and xmlns:prefix declarations stay in the attributes array in their original position. Namespace URIs are never fetched. When converting JSON to XML, prefixes must be declared on the element or an ancestor, the xml and xmlns prefixes follow their reserved rules, and a prefix cannot be undeclared with an empty value.
Why is my DOCTYPE or entity rejected?
DOCTYPE declarations are rejected as soon as the parser reaches them, so DTDs, custom and external entities and external identifiers are never processed or fetched. Only the five predefined entities (&, <, >, ", ') and numeric character references are supported. Remove the DOCTYPE and replace custom entities with their text to convert the document.
Is my XML or JSON uploaded?
No. Parsing and serialization run entirely in your browser memory. Your input and output are not sent in requests, written to analytics, logs or the URL, or saved in browser storage. Closing or reloading the page clears them.