Skip to content
ToolMug

XML to JSON Converter

Turn an XML document, feed or API response into JSON you can use in JavaScript or any modern API. Attributes and text are kept, so the JSON can be converted back to the same XML.

Runs in your browser — nothing you enter is uploaded

XML → JSON
Output (JSON)

How to use

  1. Paste XML or load the sample.
  2. Choose whether numbers and booleans should be converted.
  3. Copy the JSON or download it.

Options explained

Attributes
An attribute such as id="bk101" becomes the key "@id". Text next to attributes goes into "#text".
Repeated elements
Elements that appear more than once under the same parent become a JSON array; a single element stays an object.
Convert numbers and booleans
When on, 44.95 becomes a number and true a boolean. Turn it off to keep codes such as 00123 exactly as written.

Example

This XML, including a declaration and a comment:

<?xml version="1.0"?>
<!-- c -->
<catalog>
  <book id="bk101" in_stock="true">
    <title>XML Guide</title>
    <price currency="USD">44.95</price>
    <tag>a</tag><tag>b</tag>
    <isbn>00123</isbn>
  </book>
</catalog>

becomes this JSON with Convert numbers and booleans on:

{
  "catalog": {
    "book": {
      "title": "XML Guide",
      "price": {
        "#text": 44.95,
        "@currency": "USD"
      },
      "tag": [
        "a",
        "b"
      ],
      "isbn": 123,
      "@id": "bk101",
      "@in_stock": true
    }
  }
}

Attributes are listed after the child elements. The declaration and comment are gone, and tag became an array because it appears twice. With the option off, 44.95 stays “44.95”, isbn stays “00123” and the attribute becomes “true” as text. It affects attribute values as well as element text.

Frequently asked questions

What happens to comments and the XML declaration?

They are dropped, because JSON has no place for them. Element and attribute data is kept.

Why is a list sometimes an object instead of an array?

XML does not say whether an element can repeat. With a single occurrence the converter cannot know it is a list, so it produces an object.

What if the XML is invalid?

The first error is reported with its line number, for example a closing tag that does not match.

Privacy

This tool runs entirely in your browser. Your files and text are processed on your device and are never uploaded to our servers.

Related tools