Skip to content
Devtoolry

XML to JSON

Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the XML to JSON

The XML to JSON converter turns XML documents, feeds and SOAP responses into JSON you can use in JavaScript. Attributes are preserved and repeated elements become arrays.

Conversion happens in your browser, so your files and records stay private.

How to use the XML to JSON

  1. Paste XML or open a file.
  2. Choose the indentation.
  3. Copy or download the JSON.

Example

Convert a product feed

Input

<catalog>
  <product id="1" featured="true">
    <name>Notebook</name>
    <price currency="EUR">4.50</price>
  </product>
  <product id="2">
    <name>Pen</name>
    <price currency="EUR">1.20</price>
  </product>
</catalog>

Result

{
  "catalog": {
    "product": [
      {
        "name": "Notebook",
        "price": {
          "#text": 4.5,
          "@_currency": "EUR"
        },
        "@_id": "1",
        "@_featured": "true"
      },
      {
        "name": "Pen",
        "price": {
          "#text": 1.2,
          "@_currency": "EUR"
        },
        "@_id": "2"
      }
    ]
  }
}

Repeated <product> elements become an array, attributes become @_ keys, and an element with both an attribute and text keeps the text in #text. Numeric text becomes a number (4.50 → 4.5); attribute values stay strings.

Common mistakes

  • Arrays that are sometimes objects. A list with one <product> becomes an object, and with two an array. Code that reads the result should handle both, or always wrap the value in an array.
  • Namespace prefixes. Prefixed names such as soap:Envelope keep their prefix as part of the key. Use the full key, including the prefix, in your code.
  • Number formatting. Element text that looks like a number is converted, so 4.50 becomes 4.5 and trailing zeros are lost. Codes with leading zeros, such as 00123, and hex text stay strings.

Works well with the XML to JSON

Frequently asked questions

How are attributes represented?

Attributes become keys starting with @_ (for example @_id), next to the child elements, so no information is lost.

Why is a single child not an array?

Elements that appear once become objects; elements that repeat become arrays. Check the sample to see both.

Are comments kept?

No. JSON has no comments, so XML comments are dropped.

Can it convert SOAP responses?

Yes. The envelope and body become nested objects; navigate to the body element to reach the payload.

Guides and tutorials