Skip to content
TextArray
100% local

XML to JSON converter

Convert XML into equivalent JSON, with attributes prefixed and repeated tags as arrays.

Input

XML to JSON converter

XML and JSON both describe structured data, but the tools around you rarely speak both. An old SOAP API, an RSS feed, an Android layout, a config file or a data export hands you XML; your script, your database or your frontend wants JSON. This tool converts between them with a real parser — not a regex hack — that handles the awkward parts of XML correctly: nested elements, attributes, mixed content, self-closing tags, comments, CDATA sections, the XML declaration and DOCTYPE.

The mapping follows the widely-used convention. An element's attributes become keys prefixed with @ (configurable), so <user id="7"> gives "@id": "7". Child elements nest as objects; when a tag repeats — three <item> elements in a row — they collapse into a single array, which is exactly what you want for lists. An element that has only text becomes a plain string; one that has both text and attributes keeps its text under a #text key. Entities like &amp; and numeric references like &#65; are decoded, and CDATA content is taken literally.

Because it is a genuine recursive-descent parser, it validates as it reads: a mismatched closing tag, an unterminated comment or stray content after the root produces a clear error with the line number, rather than silently mangling the output. Choose two- or four-space indentation for a readable result, or minify to a single line for embedding.

Everything runs locally in your browser — your data never leaves your device, which matters for XML exports that often carry records and identifiers.

FAQ

How are XML attributes represented in the JSON?
As keys prefixed with @ by default (you can change the prefix). So <book lang="en"> becomes { "book": { "@lang": "en" } }. This is the convention used by libraries like xml-js and badgerfish, so the output drops into most toolchains.
What happens with repeated tags?
They become an array. Three <item> children collapse to "item": [ … ], which is what a list needs. A tag that appears once stays a single value — note that means a document with one item and another with several map to different shapes, which is inherent to XML→JSON.
Does it handle mixed content and CDATA?
Yes. An element with both text and children (or attributes) keeps its text under a #text key. CDATA sections are taken literally, so their <raw> markup and & characters survive without being parsed. Comments and processing instructions are skipped.
Why did it report an error instead of converting?
It is a validating parser: a mismatched closing tag, an unquoted attribute, an unterminated comment or content after the root element all stop the conversion with a line-numbered message. That is deliberate — a wrong-but-quiet conversion is worse than a clear error.
Is my XML uploaded anywhere?
No. The parsing and conversion run entirely in your browser and your data never leaves your device.