XML to JSON Converter

Turn XML into clean JSON. Attributes, repeated elements, and text are mapped with predictable rules, so the result is easy to use in JavaScript and APIs.

Updated
Runs in your browser. Your data is not uploaded.
Converts as you type for inputs up to 200 KB.

How to use the XML to JSON Converter

  1. Paste XML into XML input, or upload or drop an .xml file.
  2. Pick the Indent for the JSON output.
  3. Press Convert, then copy the JSON or download it as converted.json.

How it works

XML and JSON don't map one to one, so the converter uses the widely used "@ and #text" convention:

  • The root element becomes the only key of the output object.
  • An element with only text becomes a string: <title>XML</title> → "title": "XML".
  • Attributes become keys starting with @: id="b1" → "@id": "b1".
  • When an element has attributes or children as well as text, the text goes under #text.
  • Sibling elements with the same name become an array, in document order.
  • An empty element becomes an empty string. Comments and processing instructions are dropped, and CDATA content is kept as ordinary text.
  • All values stay strings, because XML has no number or boolean types.

Examples

Input:

<book id="b1">
  <title>XML Basics</title>
  <tag>xml</tag>
  <tag>data</tag>
  <price currency="USD">29.99</price>
</book>

Output:

{
  "book": {
    "@id": "b1",
    "title": "XML Basics",
    "tag": [
      "xml",
      "data"
    ],
    "price": {
      "@currency": "USD",
      "#text": "29.99"
    }
  }
}

Limitations

  • A repeated element becomes an array only when it appears more than once, so the same element can be a string in one file and an array in another. Check for both in code that reads the JSON.
  • Namespace prefixes are kept as part of the key, for example "dc:title". Namespace URIs are not resolved.
  • The order of different sibling elements is not recorded, because JSON objects are unordered.
  • Files are limited to 5 MB and must be well-formed XML.

Frequently asked questions

Why are my numbers strings in the JSON?

XML stores everything as text and has no way to say that 29.99 is a number. Keeping strings avoids turning an ID such as 007 into 7. Convert the fields you need in your code.

Can I convert the JSON back to XML?

Yes. The JSON to XML converter reads the same @ and #text keys, so a round trip gives back equivalent XML.

What happens to XML comments?

They are left out, because JSON has no comment syntax.

Is my XML uploaded?

No. The conversion happens in your browser.

Often used together with the XML to JSON Converter.