XML to JSON converter
The result appears here.
Convert
Your document never leaves the browser.
XML to JSON with attributes as @ keys and repeated elements as arrays — never uploaded.
Paste or drop an XML document and get JSON in the shape most libraries expect, with options for the two things XML cannot tell you.
The page follows the convention of Newtonsoft.Json, which fast-xml-parser and xml2js users will recognise. The root element becomes a one-key object.
The XML
<order id="7">
<item>pen</item>
<item>ink</item>
</order>The JSON it gives, at the default settings
{
"order": {
"@id": "7",
"item": [
"pen",
"ink"
]
}
}Mapping
An element with only text becomes a string; with attributes or children, an object.
Mapping
Attributes come first, as "@name" keys in source order, then children in the order they first appear.
Mapping
Text beside attributes or children is "#text".
Mapping
A name that repeats among siblings becomes an array in document order; a name that appears once is a single value.
Mapping
An empty element is "". An element with xsi:nil="true" is null.
Mapping
CDATA is ordinary text. Namespace prefixes stay in the key, like "soap:Envelope", and xmlns declarations are kept as @ keys.
Always make arrays for: XML cannot tell one <book> from a list of one book, so name the elements that should always be arrays — in the catalog sample, book makes Poetry’s single book an array like the others.
Detect numbers and booleans: XML text has no types, so everything stays a string by default. A code like 007 or a ZIP code like 02134 means what it says only as text. Turn it on and only text that is exactly a JSON number, true or false converts, with the number’s digits kept.
An order with one item
<order id="7">
<item>pen</item>
<qty>2</qty>
<zip>02134</zip>
</order>The JSON with Always make arrays for: item, and Detect numbers and booleans on
{
"order": {
"@id": "7",
"item": [
"pen"
],
"qty": 2,
"zip": "02134"
}
}A document that is not well-formed is refused at the first error, with its line and column: mismatched or unclosed tags, a second root, a bare &, an undeclared prefix. So is a DOCTYPE with an internal subset, and an entity other than the five XML predefines, because expanding them is how billion-laughs attacks work. Comments and processing instructions are dropped and counted; mixed content and a change in the order of differently named siblings are noted.
A bare &
<order id="7">
<item>pen & ink</item>
</order>✕ Line 2, column 13: An entity reference must end with a semicolon.
The conversion runs in your browser, in the same engine the editor uses. The document is never uploaded, never logged and never leaves your machine — there is no server to send it to. Once the page has loaded it keeps working with the connection off.
Going the other way?
Never. A DOCTYPE without an internal subset is ignored and noted; the page makes no network request.
Because it appears once. Name it under Always make arrays for and it is an array wherever it appears.
UTF-8 and UTF-16. A file declaring another encoding is refused, with a sentence asking for it to be saved as UTF-8.