XML to JSON Converter

Skip to editor
Explorer
Open Files

No files open

0 files open

jsoneditor.io v2

<?xml version="1.0" encoding="UTF-8"?>
<order id="ord_8F2K1" status="shipped">
  <customer>
    <name>Ada Lovelace</name>
    <email>ada@example.com</email>
  </customer>
  <items>
    <item sku="KB-104" qty="1">Mechanical keyboard</item>
    <item sku="MS-220" qty="2">Wireless mouse</item>
  </items>
  <total>138.99</total>
  <paid>true</paid>
</order>
JSONUTF-8
Spaces: 2

How do I convert XML to JSON?

To convert XML to JSON, paste it above, open Convert and press To JSON in the XML section. Elements become keys, repeated elements become arrays, attributes are kept as keys starting with @, and values that look like numbers or booleans come through as numbers and booleans.

When an element has both attributes and text, the text is kept under #text. If the XML isn't well formed, you get the parser's error and the editor keeps your original text so you can fix it.

  1. Paste your XML into the editor.
  2. Open Convert and press To JSON under XML.
  3. Copy the JSON or format it further.

Example

XML
<?xml version="1.0" encoding="UTF-8"?>
<order id="ord_8F2K1" status="shipped">
  <customer>
    <name>Ada Lovelace</name>
    <email>ada@example.com</email>
  </customer>
  <items>
    <item sku="KB-104" qty="1">Mechanical keyboard</item>
    <item sku="MS-220" qty="2">Wireless mouse</item>
  </items>
  <total>138.99</total>
  <paid>true</paid>
</order>
JSON
{
  "order": {
    "@id": "ord_8F2K1",
    "@status": "shipped",
    "customer": {
      "name": "Ada Lovelace",
      "email": "ada@example.com"
    },
    "items": {
      "item": [
        {
          "@sku": "KB-104",
          "@qty": 1,
          "#text": "Mechanical keyboard"
        },
        {
          "@sku": "MS-220",
          "@qty": 2,
          "#text": "Wireless mouse"
        }
      ]
    },
    "total": 138.99,
    "paid": true
  }
}

Questions people ask

Why is one element an object and another an array?

An element that appears once becomes a single value and one that repeats becomes an array. If your code always expects an array, wrap single values when you read them, since the XML itself carries no hint either way.

What happens to XML attributes?

They become keys prefixed with @, so <item sku="KB-104"> gives you "@sku": "KB-104".

Is my data uploaded anywhere?

No, this runs entirely in your browser, so nothing you paste is sent to a server. The only feature that sends data anywhere is the optional AI assistant, and only when you actually ask it something.