XML ⇄ JSON
Paste either format — the other one appears as you type, both directions.
How to use it
- Paste XML or JSON into the box — the result is drawn as you type, there is no button to press. The direction is detected from the first character (< for XML, [ or { for JSON) and shown above the result, so you can check it.
- If the direction was guessed wrong, pick XML → JSON or JSON → XML. The options below change with the direction: XML → JSON shows “Detect numbers & booleans”, and JSON → XML shows the “Root name” for wrapping arrays.
- Copy or download the result. Both use the exact text you see on screen; the file is named data.json or data.xml. “Load sample” fills in an example for whichever direction is active.
Example
Input (XML)
<note id="1"><to>Alice</to><from>Bob</from><body>Hi!</body></note>
Output (JSON)
{
"note": {
"@id": "1",
"to": "Alice",
"from": "Bob",
"body": "Hi!"
}
}The id attribute becomes “@id”, each child element becomes a key, and the text inside <body> becomes a string value. Switch “Detect numbers & booleans” off to keep every value — including the id — as text.
Rules, limits and known issues
- No file upload, drag-and-drop or URL fetching: paste the text in. A drop zone would eat the height the result needs, and reading files properly means handling non-UTF-8 encodings — open the file in the XML formatter (GB18030, Big5, Windows-1256) and copy the text.
- Input is capped at 1,000,000 characters; beyond 200,000 the result waits until you pause typing and says so. Above the hard cap you get an explicit error — the input is never truncated silently.
- The mapping is fixed on purpose: an element becomes an object; an attribute becomes “@name”; the element text becomes “#text”; a child element becomes a key; and several children with the same name become an array. A leaf element with only text becomes a bare string, so a deeply nested document stays readable.
- Type detection (XML → JSON) is conservative: only true / false / null (lower case only) and strict JSON numbers are converted to real types. A leading-zero integer (00501) and a 16-digit-or-longer number stay a string; everything else stays text when the switch is off. Attributes are always kept as text, never re-typed, because XML attributes are textual.
- JSON → XML needs a single root, so a top-level object uses its one key as the root element. A top-level JSON array has no single root and is wrapped in the “Root name” element, each item becoming a repeated child (named “item” by default).
- A JSON value under a key can be an object, an array, a string, a number, true / false or null. “@name” keys become attributes (null / undefined are skipped); “#text” becomes the element text; every other key becomes a child element. Arrays produce repeated elements.
- XML comments, processing instructions (<? … ?>) and the DOCTYPE are dropped and counted (they cannot be represented in JSON); CDATA is kept as text. Mixed content — text sitting next to child elements — is flattened into “#text” and its original order is not preserved; the affected elements are counted so you can see it.
- JSON is parsed strictly: no comments, no trailing commas, no single quotes, no unescaped control characters, nesting up to 64 levels. One object per line (JSON Lines) is not accepted — wrap the objects in an array first.
- XML entity references (& < >) are kept verbatim in the text and attributes (not decoded), so a round trip reproduces the exact bytes. Escaping is added on the JSON → XML side: & < > are escaped in text, and “ is escaped in attribute values.
- Out of scope: XSLT, XPath, XML Schema validation, namespaces as anything other than part of the tag name, JSON with duplicate keys (the last one wins, like JSON.parse), and preserving comment order. Nothing is uploaded, stored or put into the URL.
Related tools
What people usually need next, once the data is in the other format.