XML To JSON

Convert XML to JSON. Free XML to JSON converter.

Any well-formed XML: a declaration, comments, a DOCTYPE, attributes, namespaces, CDATA and entities are all understood. Attributes become @name keys, text beside attributes goes under #text, and elements that repeat become lists. This is the shape the JSON to XML tool reads back.

Worth a look

Rate this tool

How useful was this tool?

XML to JSON Converter

Paste or type XML into the box, load the Example, or Open a file. The JSON appears as you type, ready to Copy or Download .json.

Notes under the result say what the converter decided and what it left out: which elements became lists, which comments were dropped, and so on. The conversion runs in your browser, and nothing you paste or open leaves your computer.

Example

<?xml version="1.0" encoding="UTF-8"?>
<!-- Weekly export -->
<catalog updated="2026-10-16">
  <book id="007" lang="en">
    <title>Dune</title>
    <price currency="EUR">9.50</price>
    <tag>sci-fi</tag>
    <tag>classic</tag>
    <note/>
  </book>
  <book id="012" lang="en">
    <title>Pride &amp; Prejudice</title>
    <price currency="GBP">8.99</price>
    <tag>romance</tag>
    <summary><![CDATA[Contains <b>spoilers</b>]]></summary>
  </book>
</catalog>

With attributes as @name keys and Root element as the top key on:

{
  "catalog": {
    "@updated": "2026-10-16",
    "book": [
      {
        "@id": "007",
        "@lang": "en",
        "title": "Dune",
        "price": {
          "@currency": "EUR",
          "#text": "9.50"
        },
        "tag": [
          "sci-fi",
          "classic"
        ],
        "note": ""
      },
      {
        "@id": "012",
        "@lang": "en",
        "title": "Pride & Prejudice",
        "price": {
          "@currency": "GBP",
          "#text": "8.99"
        },
        "tag": "romance",
        "summary": "Contains <b>spoilers</b>"
      }
    ]
  }
}

What happened:

  • Attributes became @ keys. id="007" became "@id": "007".
  • Text beside an attribute went under #text. That’s the 9.50 in price, which has a currency attribute.
  • Repeated elements became lists: both book elements, and the two tags of the first book.
  • The empty <note/> became "".
  • &amp; was decoded to &, and the CDATA text was kept exactly, HTML tags included.
  • Values stayed text. "007" keeps its zeros, and "9.50" keeps its trailing zero.
  • The declaration and the comment were left out, with a note.

One or many: the list problem

Look at tag in the example. The first book has two tags, so tag is a list. The second book has one, so tag is a single string. XML has no way to say “this is a list”, so a converter can only see how many times an element actually appears.

That inconsistency trips up code that reads the JSON. A loop over book.tag works for the first book and breaks on the second. The notes name every element that became a list and remind you that elements appearing once stay single.

If your code needs a predictable shape, switch on Every child element as a list. Then every child becomes a list, even when it appears only once: "title": ["Dune"], "tag": ["romance"]. The JSON is wordier, but every book has the same structure.

Attributes

Under Attributes you can choose:

  • As @name keys. id="007" becomes "@id": "007", clearly separate from child elements. JSON to XML reads the same @ and #text convention, so a file can go from XML to JSON and back without losing its attributes. That round trip is part of the converter’s own tests.
  • As plain keys. "id": "007" sits alongside the child elements. This is simpler to use in code, but if an element has an attribute and a child with the same name, they clash.
  • Left out. Only the elements and their text are kept, and a note says the attributes were dropped.

Values stay text unless you ask

Everything in XML is text, so by default every value stays a string, exactly as written. That protects values that only look like numbers: IDs like 007, version numbers like 1.10, ZIP codes and phone numbers.

Switch on Numbers and true/false as values when you want 9.50 as a number and true as a boolean. That’s convenient for calculations, but check the IDs and versions afterwards. A JSON reader turns 1.10 into 1.1.

Namespaces

Namespaced XML uses prefixed names like g:price, which Google Merchant Center product feeds use. By default the prefixes are kept, so the JSON key is "g:price".

Switch on Remove namespace prefixes to get plain "price", which is easier to use in code. Leave the prefixes on if the file mixes two namespaces that use the same local name, or the two will clash.

What doesn’t carry over

JSON can’t hold everything XML can. The notes tell you when each of these happens:

  • Comments and processing instructions are dropped.
  • The DOCTYPE is dropped, though any entities it defines are still decoded in the text.
  • The order of mixed elements can’t always be kept. In <a/><b/><a/>, both a elements are grouped into one list, so JSON can’t record that b came between them. That rarely matters for data, but it does for documents where order means something.
  • Mixed content, like a paragraph with text and bold parts, keeps its text pieces under #text.

When the XML has a mistake

XML is strict, and one stray character makes the whole file invalid. The converter shows the line and column, marks the mistake in an excerpt, and explains it in plain words:

  • A closing tag that doesn’t match. Both tags are named, along with the line of the opening one.
  • An element that’s never closed. You’re pointed to its opening tag, not to the end of the file.
  • Two root elements, or text outside the root.
  • A stray < or &. In XML, Tom & Jerry must be written Tom &amp; Jerry.
  • An HTML entity like &nbsp;. XML only knows five named entities: &lt;, &gt;, &amp;, &quot; and &apos;.
  • Attributes without quotes or without a value, or the same attribute twice.
  • A declaration that isn’t at the very start, or control characters that XML doesn’t allow.

Many have a one-click fix:

  • Wrap everything in a root element.
  • Write a stray < as &lt;.
  • Fix the & signs, turning HTML entities like &nbsp; into character references like &#160;.
  • Remove control characters.
  • Remove whatever comes before the declaration.

Options

  • Indent: 2 spaces, 4 spaces, or None (one line).
  • Attributes: as @name keys, as plain keys, or left out.
  • Root element as the top key: keep the root’s name as the outer key ({"catalog": {...}}), or start directly with its contents.
  • Every child element as a list: for a predictable shape.
  • Numbers and true/false as values: off by default.
  • Remove namespace prefixes.

FAQ

What kind of XML can I convert?

Any well-formed XML: API and SOAP responses, RSS and Atom feeds, XML sitemaps, product feeds, configuration files and data exports.

Can I paste HTML?

HTML usually isn’t valid XML, because of unclosed tags like <br>, attributes without quotes and entities like &nbsp;. If you paste HTML, a tip explains what XML needs instead. If you paste JSON, a note points you to the JSON Beautifier.

Can I convert JSON back to XML?

Yes, with JSON to XML. Use attributes as @name keys here, and the attributes come back too.

How do I explore the result?

Open it in the JSON Viewer to browse it as a tree and copy the path to any value. To turn repeated records into a spreadsheet, use JSON to CSV.

Is my data uploaded anywhere?

No. Everything happens in your browser, and nothing you paste or open is stored.

Note: All processing is done client-side. We do not store or see your data.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us