Convert XML to JSON!

Input XML to convert it into JSON! Handy for SOAP responses and RSS feeds.
XML
Result
 

Convert XML to JSON!

Convert an XML document into a JSON object. Attributes become @name keys and repeated child elements are grouped into arrays, so deeply nested documents such as SOAP responses or RSS feeds can be read like a JavaScript object.

Use it to understand the structure of an XML response from a legacy system before handling it in front-end or Node.js code, or to turn it into a JSON mock for tests. Parsing is done by your browser's DOMParser.

How to use

  1. Paste the document into the XML box or drop an .xml file onto it. The <?xml ...?> declaration is optional.
  2. Unclosed tags or other syntax errors show the browser parser's error message in the result.
  3. Review the JSON under Result, keyed by the root element name, and copy it.

Example

Input (XML)
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetRateResponse>
      <rate currency="USD">1342.5</rate>
      <note><![CDATA[rates < 1 hour old]]></note>
      <holiday/>
    </GetRateResponse>
  </soap:Body>
</soap:Envelope>
Output (JSON)
{
  "soap:Envelope": {
    "@xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
    "soap:Body": {
      "GetRateResponse": {
        "rate": {
          "@currency": "USD",
          "#text": "1342.5"
        },
        "note": "rates < 1 hour old",
        "holiday": null
      }
    }
  }
}

The currency attribute became @currency, and the number inside the element went into #text as the string "1342.5". The < inside CDATA is kept as plain text, and the empty <holiday/> is null.

Supported features

  • Output is shaped { "rootName": ... }, preserving the original root element name.
  • Attributes use @-prefixed keys; text that sits alongside child elements or attributes goes under #text.
  • Text-only elements become strings and empty elements become null.
  • Two or more sibling elements with the same name are grouped into an array.
  • CDATA sections are read as text; comments and processing instructions are ignored.
  • Namespace-prefixed names like soap:Body and xmlns declaration attributes are kept as keys.

Use cases

Understanding a SOAP response

Seen as JSON, the Envelope → Body → Response nesting shows exactly where the payload sits, and that path maps directly to property access in your code.

Inspecting RSS or Atom feeds

Check how many item entries a feed has and where the url attribute of enclosure lives before writing the parsing code.

Turning XML responses into JSON fixtures

When building a BFF or adapter around an XML API, converting real responses to JSON gives you test fixtures straight away.

Notes and limitations

  • Every value is a string; even <price>12.5</price> is not converted to a number, so convert where needed.
  • A single child comes out as an object, not a one-element array. The same response can change shape with the number of items, so check with Array.isArray in code.
  • Mixed content such as <p>hello <b>world</b> again</p> has its text merged into one #text, losing where it sat between elements.
  • Leading and trailing whitespace in text is trimmed.

FAQ

Can numbers and booleans be typed?

XML carries no type information beyond text, so the tool does not guess and keeps strings. That way code values like "00123" are never mangled into numbers.

I want an array even when there is only one element.

There is no option for this. Wrapping in code with Array.isArray(x) ? x : [x] is the simplest fix.

Can the JSON be turned back into XML?

The JSON to XML tool uses the same @ and #text conventions, so feeding it this output produces XML again. Comments, the CDATA distinction and the position of text in mixed content are not restored.