XML to JSON Converter

Paste XML and get JSON that keeps elements, attributes and text, so you can work with it in JavaScript or APIs.

JSON

Convert XML documents to JSON

XML and JSON model data differently: XML has attributes, text nodes and repeated elements, while JSON only has objects, arrays and values. This converter uses a compact, lossless mapping. Each element becomes a key, attributes are collected under _attributes, text content is stored under _text, and an element that appears more than once becomes an array. The XML declaration is kept under _declaration. Because nothing is thrown away, you can edit the JSON and convert it back to XML with the JSON to XML converter.

How to use

  1. Paste the XML, for example a SOAP response, an RSS feed or a Maven pom.xml.
  2. Read the JSON in the output editor; parsing errors show the line where the XML is malformed.
  3. Copy the JSON, or press Swap to convert it back to XML.

Frequently asked questions

Why are numbers in my XML converted to strings?
XML has no data types: everything inside an element is text. The converter keeps values as strings under _text so nothing is guessed incorrectly, for example a ZIP code with a leading zero.
Why is an element sometimes an object and sometimes an array?
A single element becomes an object, and repeated sibling elements with the same name become an array. If your code must handle both, check with Array.isArray or normalize the value into an array.
What do _attributes and _text mean?
_attributes holds the element's attributes as key-value pairs, and _text holds its text content. Using fixed names keeps attributes and child elements from colliding.

Example: XML to JSON

XML input

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101">
    <title>XML Developer's Guide</title>
    <price>44.95</price>
  </book>
  <book id="bk102">
    <title>Midnight Rain</title>
    <price>5.95</price>
  </book>
</catalog>

JSON output

{
  "_declaration": {
    "_attributes": {
      "version": "1.0",
      "encoding": "UTF-8"
    }
  },
  "catalog": {
    "book": [
      {
        "_attributes": {
          "id": "bk101"
        },
        "title": {
          "_text": "XML Developer's Guide"
        },
        "price": {
          "_text": "44.95"
        }
      },
      {
        "_attributes": {
          "id": "bk102"
        },
        "title": {
          "_text": "Midnight Rain"
        },
        "price": {
          "_text": "5.95"
        }
      }
    ]
  }
}

Other conversions