Convert XML to JSON

Turn XML into JSON objects.

0 lines · 0 characters

0 lines · 0 characters

Results update as you type.

Runs in your browser. Nothing uploaded.

How to convert XML to JSON

  1. Paste your XML into XML, such as an API response, a feed or an exported file.
  2. Leave Keep attributes on to include attributes as @ keys, or turn it off to keep only element content.
  3. Copy or download the JSON. If the XML is broken, the status line gives the line and the reason instead.

How XML maps to JSON

XML JSON
<name>Ada</name> "name": "Ada"
<total currency="EUR">189.90</total> "total": { "#text": 189.9, "@currency": "EUR" }
Two <item> elements "item": [ ... ]
<note/> "note": ""
Tom &amp; Jerry "Tom & Jerry"
<media:title> "media:title"

Entities like &amp; and &lt; are decoded, CDATA content becomes plain text and namespace prefixes stay part of the key name. Spaces at the start and end of text are trimmed.

Where XML and JSON don’t line up

XML documents that mix text and tags, like <p>Hello <b>world</b> again</p>, don’t convert cleanly. The text pieces are joined into one value and you lose where the tags sat, so this kind of XML is better processed as a document than as data.

Values can also change type: plain numbers and true or false become JSON numbers and booleans. Codes with leading zeros, such as ZIP codes and product numbers, are kept as text so their zeros survive. An XML declaration like at the top is skipped, since it describes the file rather than the data.