XML to JSON

Input
Output

XML to JSON Converter

Paste XML and get JSON you can actually work with. Repeated elements become arrays, attributes are kept, and numbers and booleans can be detected or kept as text.

Example: an order with attributes and repeated elements

Attributes become keys starting with @, an element's text next to attributes goes in #text, the two item elements become an array, and numbers and true are detected:

Input

<?xml version="1.0"?>
<order id="ORD-20419" paid="true">
  <customer>Ananya Rao</customer>
  <item sku="KB-01" qty="1">Keyboard</item>
  <item sku="MS-02" qty="2">Mouse</item>
  <total currency="INR">4097</total>
</order>

Output

{
  "order": {
    "@id": "ORD-20419",
    "@paid": true,
    "customer": "Ananya Rao",
    "item": [
      {
        "@sku": "KB-01",
        "@qty": 1,
        "#text": "Keyboard"
      },
      {
        "@sku": "MS-02",
        "@qty": 2,
        "#text": "Mouse"
      }
    ],
    "total": {
      "@currency": "INR",
      "#text": 4097
    }
  }
}

How do I use the XML to JSON?

  1. Paste XML or open an .xml file.
  2. Choose whether to detect numbers and booleans.
  3. Copy or save the JSON.

What does the XML to JSON do?

  • Repeated elements become arrays
  • Attributes kept alongside child elements
  • Switch direction for JSON to XML

When to use the XML to JSON

SOAP services, RSS and Atom feeds, sitemaps, Android resources, Maven files and many bank and government APIs still speak XML. Converting it to JSON lets you query it with jq or JSONPath, compare two responses with Diff, or hand it to code that only knows JSON.

Elements become keys, attributes become keys starting with @, and an element's text next to attributes or children goes in #text. Elements that repeat become an array, and numbers and true/false are detected unless you keep every value as text. Values with leading zeros, like 007, stay text either way.

Frequently asked questions

Why is one item an object but several are an array?
XML doesn't say whether an element can repeat, so a single <item> becomes an object and two or more become an array. If your code always expects an array, wrap single values when you read them.
Are namespaces kept?
Prefixes stay in the names, so <soap:Body> becomes the key soap:Body, and namespace declarations become attributes such as @xmlns:soap.
What happens to XML attributes?
They become keys starting with @, like @id, so no data is lost.
Is my data uploaded?
No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.

More JSON tools

Bracely has 108 JSON tools in one page. Related ones:

Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram