XML to JSON converter

Convert XML to JSON with attributes kept as "@_name" keys and element text as "#text", so nothing is silently lost: repeated elements become arrays, and the JSON is checked by turning it back into the same XML.

XML

JSON

Waiting for input

What you get

How each result is checked

  1. Your XML is checked for well-formedness first; errors show the line number.
  2. The JSON is turned back into XML and parsed again, and every element and attribute must match the original.
  3. Every word of text and every attribute value is also read from your XML independently, with its own reader, and must be in the JSON, so text cannot be dropped or left undecoded.

What can't convert exactly

  • Number detection only converts values whose text stays identical, so 007, 1.50, 1e3, +1 and 20-digit IDs stay text.
  • Comments are not carried over, and CDATA becomes plain text.
  • Character references such as A or 😀 are decoded. HTML names such as   are not part of XML; they are kept as text, and the result says so.
  • In elements that mix text with child elements (<p>a <b>x</b> c</p>), JSON cannot keep the order of text and children: the text pieces are joined with a space into "#text", and the result names the element.
  • Namespaces are kept: prefixed names such as soap:Body stay as they are, and xmlns declarations become "@_xmlns" keys.

Questions

Why are some elements arrays and others objects?

Repeated elements become arrays; a single element becomes an object. That is how XML maps to JSON without a schema.

Are elements named "constructor" or "__proto__" handled?

Yes. They are converted as normal data, with protection against JavaScript object tricks.

How do I convert XML to JSON with attributes?

Paste your XML: attributes are kept automatically as keys starting with "@_", such as "@_id": "bk101". To go back, paste that JSON into JSON to XML and the attributes return.

Can I convert RSS feeds, SOAP messages or SVG to JSON?

Yes. Namespaced names such as soap:Body or atom:link are kept, CDATA becomes text, and character references are decoded. Paste the XML or open the .xml file.

How do I convert XML to JSON online?

Paste your XML or open a file on the left (or click Example). The JSON appears on the right as you type, already checked. Copy it, or download it as a file. Nothing is uploaded.

Can the JSON output be wrong?

Every result is checked before it is shown (the checks are listed on this page). If a check fails, the page says "Review needed" and why, instead of presenting the output as correct, and anything that cannot convert exactly is named in the notes.