XML to JSON tree
Convert XML with mixed text and elements to an order-preserving JSON tree.
- 1Add input
- 2Review and run
- 3Get your result
Tool input and files are processed in this browser without being uploaded.
Before you start
Convert XML with mixed text and elements to an order-preserving JSON tree. Inspect name, attrs and children instead of losing text order in a grouped object mapping.
How to use this tool
- Paste XML or select a UTF-8 .xml or .txt file.
- Check the root and counts, then convert to the ordered JSON tree.
- Inspect mixed children and attributes; copy or download the complete JSON.
Supported inputs and limits
XML 1.0 and UTF-8 only. DTD declarations and external entities are rejected. Pasted text is limited to 1 MiB; a file to 10 MiB; the tree to 200,000 elements and 128 levels.
Children retain source order. Adjacent text and CDATA are combined; comments and processing instructions inside the root are retained, while those outside it are omitted.
This is a structural tree, not a domain-specific schema. Files are processed in this browser.
Worked example
Example input
<user id="7">Mori</user>
Example options
{}Example output
{
"name": "user",
"attrs": {
"id": "7"
},
"children": [
"Mori"
]
}When something does not work
Correct malformed XML, use UTF-8 and XML 1.0, or remove DTD declarations. Check the target importer’s expected JSON shape.
Frequently asked questions
Will text stay in the right place between elements?
Yes. The children array follows XML source order, including text, elements, in-root comments and processing instructions. Adjacent text and CDATA become one text node.
Does it preserve namespaces and external entities?
Element namespace URIs and qualified names are retained. DTD declarations and external entities are rejected; this tool does not resolve external resources.
Is this JSON accepted by my importer?
The output uses a name/attrs/children tree. Check whether your importer expects that shape; it is not a generic business-object mapping.
Documentation & further reading
Related tools
JSON formatting workspace
Format or minify strict JSON, sort object keys, and encode or decode strings while preserving raw number tokens.
Regex tester
Try a pattern and see what it matches in your text.
Compare text
See what changed, side by side.
HTML formatter
Format HTML indentation so its structure is easier to read.