devtools

XML to JSON Converter

Convert XML to JSON in your browser: repeated tags become arrays, attributes map to @attributes, and mixed text to #text. Private, offline, and no uploads.

Runs entirely in your browser — your data never leaves your device.

How to use XML to JSON Converter

What it does & when you need it

You have an XML document — a SOAP response, an RSS feed, an old configuration file, a sitemap — and the rest of your stack speaks JSON. This converter reads XML with a real parser and emits pretty-printed JSON you can drop into a JavaScript object, a test fixture, or a jq pipeline. It runs entirely in your browser, so an internal payload full of hostnames and IDs never leaves your machine.

How to use

  1. Paste your XML into the input.xml buffer, press Sample for an example, or Upload an .xml file.
  2. Read the JSON in output.json as it updates live. If the document is malformed, the status bar names the problem — a mismatched tag, an unclosed element, or stray content after the root.
  3. Press Copy JSON or Ctrl/Cmd + Enter to copy the result, then send it to the JSON Formatter if you want to re-indent or validate it further.

Things worth knowing

Repeated tags become arrays. A tag that appears once maps to a single value; the same tag repeated under one parent maps to an array. That is the natural fit for a list, but it means the shape depends on your data — one <item> looks different from three, so code defensively if a list can hold a single element.

Attributes and text get reserved keys. Attributes are gathered under an @attributes object, and when an element mixes its own text with child elements that text lands under a #text key. A plain <name>Ada</name> simply collapses to the string "Ada".

The conversion is deliberately lossy. Comments and processing instructions are dropped, the order between mixed text and elements is not preserved, and namespace prefixes survive only as part of the tag name. Entities such as &amp; and &#65;, plus CDATA sections, are decoded to their literal text. Going the other direction? Use JSON to XML.

Examples

Attributes and repeated children

<user id="1">
  <name>Ada Lovelace</name>
  <role>admin</role>
  <role>editor</role>
</user>

The id attribute lands under @attributes and the two <role> tags collapse into an array.

Self-closing and nested elements

<page>
  <title>Home</title>
  <hr/>
  <meta charset="utf-8"/>
</page>

The empty <hr/> becomes an empty string; <meta> keeps its attribute under @attributes.

Mixed text and markup

<p>Hello <b>world</b>!</p>

The element has both text and a child, so the text is placed under a #text key.

Frequently asked questions

How are repeated XML tags represented in the JSON?

A tag that appears once becomes a single value, and a tag that repeats under the same parent becomes an array. So one <item> is an object or string, while three <item> siblings become an array of three. This mirrors how a list is naturally modelled, but it means the shape can change if your sample data happens to have only one element where more are possible.

Where do attributes and text go?

Attributes are gathered into an "@attributes" object on the element, so <user id="1"> yields { "@attributes": { "id": "1" } }. When an element has both attributes or child elements and its own text, that text is stored under a "#text" key. A plain element with only text, like <name>Ada</name>, collapses to just the string "Ada".

Are entities and CDATA decoded?

Yes. The five predefined entities (&amp; &lt; &gt; &quot; &apos;) and numeric character references such as &#65; and &#x41; are decoded to their characters in both text and attribute values. CDATA sections are read as literal text, so <![CDATA[<b>]]> becomes the string "<b>".

What is lost when converting XML to JSON?

The conversion is intentionally lossy: comments and processing instructions are dropped, namespace prefixes are kept only as part of the tag name, and the relative order of text and elements in mixed content is not preserved because sibling text is concatenated. Whitespace between elements used purely for indentation is treated as insignificant and trimmed.

Is my XML uploaded anywhere?

No. Parsing and serialization run entirely in your browser with a hand-written parser, so a config file or SOAP payload full of internal hostnames never leaves your machine, and the tool keeps working offline once the page has loaded.