Convert XML to JSON

Runs on your device · Your file never leaves your device.

Drop an .xml file or paste XML from an API, a feed or a configuration file and get JSON you can work with. The document is read by the browser’s own XML parser, so anything that is well-formed converts, and a malformed file is reported with the line and column of the problem.

The mapping is fixed and reversible: each element becomes a key; siblings with the same name become an array; attributes are kept under keys starting with @ (id="3" becomes "@id": "3"); and when an element holds both text and children or attributes, the text goes under "#text". An element with only text becomes the value itself.

With type detection on, text such as 12, true or an empty element becomes a number, a boolean or null; switch it off to keep everything as text. Namespaced names (soap:Body) are kept as written. The preview shows the first 200 lines before you download.

How to convert XML to JSON

  1. Drop an XML file, or paste XML into the box.
  2. Decide whether numbers, booleans and empty elements should be typed.
  3. Press Convert to JSON and check the preview.
  4. Download the .json.

Supported formats and limits

Input
XML (.xml) — a file or pasted text, UTF-8
Output
JSON, pretty-printed, UTF-8
Attributes
Kept as "@name" keys
Repeated elements
Become an array
Where it runs
In your browser; nothing uploaded

Not for: Documents that are not well-formed XML (unclosed tags, HTML pages) — the parser reports the first problem rather than guessing.

Frequently asked questions

Are my files uploaded to a server?
No. This conversion runs entirely inside your browser using your own device’s processing power. The file never leaves your computer or phone, which is why it also works when your connection drops.
How are attributes and mixed content handled?
Attributes become keys prefixed with @, so <item id="3"> gives "@id": "3". If an element has text as well as attributes or child elements, the text is stored under "#text"; an element with text only becomes that text directly.
Why is one element an object and the repeated ones an array?
An element that appears once under its parent becomes an object (or a value); two or more siblings with the same name become an array. That mirrors the document exactly, so a list of one item is one object — if your code needs an array in both cases, wrap it on the receiving side.
What does the top of the JSON look like?
One key named after the root element, holding everything inside it — <records>…</records> becomes {"records": {...}}. That keeps the root name so the JSON to XML tool can rebuild the same document.

More in Spreadsheets & data

Related tools