XML to JSON Converter
Convert well-formed XML to JSON — character data stays text, attribute names keep their @ prefix.
Input
Well-formed XML 1.0 as text. DTDs, entity expansion and processing instructions are rejected.
Result
This pane stays empty until a conversion succeeds; Copy and Download unlock with it.
Details
Mapping notes and run statistics appear here after a conversion. No numbers are shown before that.
Mapping notes
Run statistics
The xml-json-v1 mapping
Conversion is deterministic: the same document always produces the same JSON. The rules below are the whole mapping, applied in this order. For a worked namespace walkthrough, seeXML namespaces: prefixes, xmlns, and JSON keys.
| XML | JSON | Example |
|---|---|---|
| character data in a leaf | JSON string, never a number | <unit>001240.50</unit> → "001240.50" |
| attribute | key prefixed with @ | id="A-1042" → "@id": "A-1042" |
| namespace declaration | attribute too, as @xmlns or @xmlns:pfx | xmlns:p="urn:x" → "@xmlns:p": "urn:x" |
| leaf without attributes | the string itself | <qty>2</qty> → "qty": "2" |
| text plus attributes, no child elements | text under #text | see the sample output |
| repeated siblings with one qualified name | one array in document order | two <item> → "item": [ …, … ] |
| qualified element name | kept verbatim, prefix included | <p:width> → key "p:width" |
| whitespace-only text between children | dropped as indentation | — |
One child element is not forced into an array, so a document with a single <item> produces an object, not a one-element array. Text together with child elements in one element is rejected as mixed_content_unsupported instead of being flattened, because flattening would lose the order of text and markup.
How a conversion run works
What is rejected
- Document type declarations and every DTD form, so no entity expansion can happen.
- Processing instructions other than the XML declaration.
- Mixed content, as above.
- Documents over 1,000,000 characters or 1,000,000 UTF-8 bytes, deeper than 256 levels, over 100,000 nodes, over 128 attributes on one element, or with names longer than 1024 characters.
The input must already be decoded text: a declared encoding is not applied. This converter does no XSD validation, XPath, XSLT or XInclude.
Limits of a run
Conversion runs in a Web Worker in this browser tab. Job ids are generated by the page. Cancelling terminates the worker and any answer arriving after that is discarded. A run is stopped after 20 seconds. Error messages name the reason and a position in the document, never a fragment of your text. This page processes the document in this browser and has no document-upload feature. Hosting requests may still produce ordinary service metadata; this is not an absolute privacy guarantee.
Reading the output
Mapping notes are derived from the output you just produced: how many attribute keys were written, how many #text members appeared, how many sibling groups became arrays. Run statisticsreport element, attribute, node and depth counts plus the engine time.Copy JSON and Download JSON export exactly the text in the result pane; if the browser refuses clipboard access the page says so instead of claiming a copy.
Guides
- XML namespaces: prefixes, xmlns, and JSON keys — what namespace names, prefixes and qualified names mean, and how
a:itemand@xmlns:psurface in the JSON output.
Other reading is indexed in the guides hub.