Skip to content

XML to JSON Format Converter

Converts XML to JSON with xml-js in compact mode: attributes go under _attributes, text under _text, and repeated sibling elements become an array. All values stay strings.

Inspecting a SOAP, RSS or legacy XML API response as JSON before writing parsing code.

When to use it

  • Inspecting a SOAP, RSS or legacy XML API response as JSON before writing parsing code.
  • Pulling attribute and text values out of an XML export to feed into JSON-based tooling.

How to use

  1. Paste XML or load an .xml file into the left editor.
  2. In the JSON, read attributes from _attributes, element text from _text, and repeated elements from arrays.
  3. Copy the JSON and map the fields you need into your own structure.

XML input

<order id="1042">
  <customer>Ada Lovelace</customer>
  <item sku="A-1">Keyboard</item>
  <item sku="B-7">Mouse</item>
</order>

JSON

{
  "order": {
    "_attributes": {
      "id": "1042"
    },
    "customer": {
      "_text": "Ada Lovelace"
    },
    "item": [
      {
        "_attributes": {
          "sku": "A-1"
        },
        "_text": "Keyboard"
      },
      {
        "_attributes": {
          "sku": "B-7"
        },
        "_text": "Mouse"
      }
    ]
  }
}

Details and limitations

Conversion runs in the browser. There are no settings; the compact format is fixed.

An element that appears once is an object, but twice it becomes an array, so the JSON shape can change with the data. Handle both in code.

The XML declaration, comments and CDATA are kept as _declaration, _comment and _cdata. No schema (XSD) or DTD validation is done.

Mixed content (text interleaved with tags) loses its original ordering.

FAQ

Are numbers and booleans converted to JSON types?

No. Attribute values and text stay strings, e.g. "1042". Convert types in your own code where needed.

What happens if my XML is malformed?

The page shows an "Invalid XML" error instead of JSON, such as "unclosed tag <order>" or "Unexpected close tag (line 3, column 8)". Close every element, quote attribute values and escape & as &amp;.

Can I get JSON without _text and _attributes keys?

Not on this page. The compact format keeps them so attributes and text are not confused. Reshape the result in code after copying.

Specifications and references