XML to JSON Converter

Convert XML to JSON with a documented convention (@attributes, #text) and a clear list of what is lost: order across different elements, comments and namespace declarations.

Options

Input

Up to 5 MiB. The file is not uploaded: it is read in your browser.

Ctrl + Enter to run

Result

Converts XML to JSON with an explicit convention: attributes get an “@” prefix, text of an element with attributes or children goes into “#text”, repeated elements become an array and empty elements become null.

Because XML and JSON are not equivalent, the tool tells you what is lost: relative order across differently named elements, text position in mixed content, comments and namespace resolution.

How to use it

  1. Paste the XML.
  2. Pick the indentation.
  3. Press Run and review the information-loss warnings.

Example

Example input
<order id="42"><customer>Ana</customer><item sku="A-1">Teclado</item><item sku="B-2">Ratón</item><gift/></order>
Result
{
  "order": {
    "@id": "42",
    "customer": "Ana",
    "item": [
      {
        "@sku": "A-1",
        "#text": "Teclado"
      },
      {
        "@sku": "B-2",
        "#text": "Ratón"
      }
    ],
    "gift": null
  }
}

Limitations

  • All values are strings: numbers and booleans are not inferred.
  • An element appearing once is not an array even if other documents repeat it.
  • Namespace prefixes are part of the name; they are not resolved to their URI.

FAQ

Can I go back from this JSON to the original XML?
Not always: order across different siblings, comments and mixed-text position are lost. Use it to read data, not as a round-trip format.
Why are numbers not converted?
Because everything in XML is text, and guessing types can change data such as postal codes or IDs with leading zeros.

Related tools

References