Skip to content
Utilerio

XML to JSON

Convert XML documents to readable JSON without touching a server.

JSON output

The result will appear here.

Was this tool useful?

About this tool

XML and JSON describe the same kind of data with different assumptions. XML separates attributes from child elements and has no native concept of an array; JSON has arrays and objects but no attributes. Every converter therefore has to make choices, and knowing which ones it made is what stops the output surprising you later.

This one prefixes attributes so they never collide with element names, and promotes a repeated element to an array.

How to use it

  1. Paste your XML or upload a .xml file.
  2. Decide whether to keep attributes. When they are kept, each one appears as a key with the prefix you choose — @_ by default.
  3. Turn numeric conversion on if you want 42 to become a number rather than the string "42".
  4. Convert, then copy or download the JSON.

Examples

Attributes and nested elements

<order id="1001">
  <customer>Utilerio</customer>
  <item sku="TL-001">Label roll</item>
</order>
{
  "order": {
    "@_id": "1001",
    "customer": "Utilerio",
    "item": { "@_sku": "TL-001", "#text": "Label roll" }
  }
}

Common problems

A list has one item and does not come out as an array.
XML cannot express "this is a list of one". A converter can only see one element and produces an object. Code that consumes the result should normalise: wrap a non-array in an array before iterating.
The document is rejected because it has a DOCTYPE.
DOCTYPE declarations can define entities that read files off the server — the XXE class of attack. This tool refuses them outright. Delete the declaration and convert the remaining document.
Namespaced element names carry a prefix into the JSON.
Prefixes such as ns: are part of the element name and are preserved. Strip them in your own mapping step if the consumer does not expect them.

Frequently asked questions