Skip to content

XML to JSON Converter

Turn XML into clean JSON with control over attributes, arrays and types.

Options
Runs in your browser — your XML is not uploaded. External DTDs are never fetched.

How to use

  1. Click Paste to insert XML from your clipboard, or Upload to select a file.
  2. Choose an Attribute prefix, or turn on Ignore attributes to leave attributes out.
  3. Set Arrays to Auto (2+ same tags) or Always.
  4. Click Convert if it appears; otherwise, conversion updates as you edit.
  5. Click Copy to copy the JSON, or Download to save a .json file.

Examples

Product catalog with attributes and repeated items

Input
<catalog>
  <product sku="MUG-101">Blue coffee mug</product>
  <product sku="MUG-102">White coffee mug</product>
</catalog>
Output
{
  "catalog": {
    "product": [
      {
        "@sku": "MUG-101",
        "#text": "Blue coffee mug"
      },
      {
        "@sku": "MUG-102",
        "#text": "White coffee mug"
      }
    ]
  }
}

Inventory with typed values and a single-item array

Input
<inventory>
  <item>
    <sku>007</sku>
    <quantity>12</quantity>
    <available>true</available>
    <supplierId>12345678901234567890</supplierId>
    <note/>
  </item>
</inventory>
Output
{
  "inventory": {
    "item": [
      {
        "sku": [
          "007"
        ],
        "quantity": [
          12
        ],
        "available": [
          true
        ],
        "supplierId": [
          "12345678901234567890"
        ],
        "note": [
          null
        ]
      }
    ]
  }
}

Namespaced configuration with comments

Input
<cfg:settings xmlns:cfg="urn:example:settings">
  <!-- Staging environment -->
  <cfg:endpoint>https://api.example.com/v1</cfg:endpoint>
  <cfg:region>us-east-1</cfg:region>
</cfg:settings>
Output
{
  "@xmlns:cfg": "urn:example:settings",
  "#comment": "Staging environment",
  "endpoint": "https://api.example.com/v1",
  "region": "us-east-1"
}

FAQ

Is my XML uploaded when I convert it online?

Your XML is parsed and converted in your browser, not uploaded, and external DTDs or entities are never fetched. Analytics events contain the tool slug, not your XML or JSON.

Can I convert the JSON back to the same XML?

Swap opens JSON to XML with your current attribute prefix and text key, but it is not a lossless round trip. Conversion drops the XML declaration, DOCTYPE and processing instructions, and can lose the order of mixed text and alternating child elements.

Why is my XML not converting to JSON?

Invalid XML leaves the JSON output empty and shows errors with line and column numbers. Click an error message to jump to it; check for mismatched tags, unquoted attributes, unescaped & characters or more than one root element.

How large an XML file can I convert?

Files larger than 50 MB are rejected. Above 1 million input characters, use Convert instead of live conversion; your browser may still run out of memory, so try a smaller file if that happens.

Does the converter support XML entities and CDATA?

It decodes predefined XML entities, numeric character references and entities declared in an internal DOCTYPE subset; CDATA content is taken as text. HTML entities such as &nbsp; are not predefined in XML, so use &#160; for a non-breaking space.