XML to JSON Converter

Convert XML to JSON in your browser. Attributes, namespaces and mixed text are kept. Copy or download the JSON.

Loading tool…

How it works

Paste XML

Paste XML, open a file up to 5 MB, or drop one on the box. It is read in this tab and never uploaded.

Pick the options

List tags that should always be arrays. Turn on number conversion if you want 42 instead of "42".

Copy or download

Copy the JSON or download it as a .json file.

How is XML mapped to JSON?

Attributes become "@name" and text becomes "#text". XML names cannot start with @ or #, so these keys never clash with a child tag. Repeated tags become an array. An empty tag is null (<x/> and <x></x> are the same), a tag with only text is a string. Prefixes stay as written, like a:root, and xmlns attributes are kept.

Source: XML 1.0 §2.3 Names · §3.1 Empty tags

What does JSON lose?

The order between text and tags, and between different tags (<x/><y/><x/>). Comments, processing instructions, the DOCTYPE and whitespace-only text are dropped, unless xml:space="preserve" keeps the whitespace. Default attribute values from the DOCTYPE are filled in. CDATA becomes plain text, entities are decoded, CRLF line ends become LF, and line breaks and tabs in attribute values become spaces. With number conversion on, 42 and "42" look the same.

Source: §2.5 Comments · §2.7 CDATA · §2.10 White space · §2.11 Line ends · §3.3.2 Attribute defaults · §3.3.3 Attribute values

Why is my XML rejected?

It must be well-formed: one root element, every tag closed. Besides &amp; &lt; &gt; &quot; &apos;, named entities like &nbsp; need a declaration, and documents that declare entities are refused, because expanding them can freeze the tab. Use numeric references like &#160; instead. External DTDs are not fetched.

Source: §2.1 Well-formed · §4.1 References · §4.6 Predefined entities

Which values become numbers?

Only with the option on, and only when the whole value is a JSON number that reads back as the same text: 42, -3.5, 1.5e-7. So 007, 1.0, 1e3, -0 and integers past 2^53 - 1 (positive or negative) stay strings. Only true and false become booleans.

Source: RFC 8259 §6 Numbers

Need data from a website, not a file?

Browser Use agents open pages in a real browser, including dynamic ones, and return structured data.