Text and developer tools

XML ↔ JSON Converter

Convert XML to JSON and back.

Convert
0 characters

Your text stays on your deviceHow?

How XML and JSON map
8 rows
XMLJSON
<title>Tea</title>"title": "Tea"
<book id="7">…</book>"book": { "@_id": "7", … }
<price currency="GBP">12.50</price>"price": { "@_currency": "GBP", "#text": "12.50" }
<tag>a</tag><tag>b</tag>"tag": ["a", "b"]
<empty/>"empty": ""
<note><![CDATA[<b>]]></note>"note": "<b>"
<?xml version="1.0"?>"?xml": { "@_version": "1.0" }
<!-- a comment -->Left out: JSON has no comments

How to convert XML to JSON

  1. Choose XML to JSON or JSON to XML.
  2. Paste your XML or JSON into the box.
  3. Copy the result, or fix the error at the line and column shown.

Questions

How are attributes written in JSON?

As keys that start with @_, so id="7" becomes "@_id". Text next to attributes or child elements goes under "#text". The table on the page shows every rule.

What happens to repeated elements?

Elements with the same name under one parent become a JSON list, and a list in JSON becomes repeated elements in XML.

Are numbers turned into JSON numbers?

No. Every value stays text exactly as written, so 007 keeps its zeros and the XML comes back the same.

Are comments kept?

No. JSON has no comments, so XML comments are left out. CDATA sections become plain text.

Is my data uploaded?

No. It is converted inside your browser, and never leaves your device.