Skip to content
ToolZone

XML → JSON

Convert XML data into JSON format, useful when migrating a system from XML-based APIs or configuration to a more modern JSON structure.

Runs in your browser. Nothing you enter or upload leaves your device.

XML
Indent
JSON output…

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the XML → JSON

This XML to JSON converter parses XML in your browser and outputs indented JSON while you type. It is meant for developers, analysts and integrators who need to inspect or reuse XML data from feeds, legacy APIs or config files in a JSON-based workflow.

How it works

The tool uses the browser's built-in XML parser (DOMParser). If the parser reports an error, the message is shown with the line and column, plus a snippet of the surrounding XML. Otherwise it walks the tree from the root element, and the root's name becomes the top-level key.

Attributes become keys with the prefix you choose (@ by default). An element with only text becomes that text; text alongside attributes or child elements, including CDATA, is stored under "#text". Repeated sibling tags are collected into arrays, or every child becomes an array if you tick that option. Values stay strings unless you tick Convert numbers & booleans.

How to use

  1. 1

    Paste your XML or open an XML file.

  2. 2

    Choose options: include attributes and their prefix, convert numbers, always use arrays, empty elements as null.

  3. 3

    If the XML is invalid, fix the line shown in the error.

  4. 4

    Copy or download the JSON, with 2 or 4 space indentation or minified.

Worked examples

Repeated elements become an array

Converting a small product list.

Input
<products><product id="1">Pen</product><product id="2">Notebook</product></products>
Result
{ "product": [ { "@id": "1", "#text": "Pen" }, { "@id": "2", "#text": "Notebook" } ] }

Nested elements

A simple user record.

Input
<user><name>Ana</name><address><city>Lisbon</city></address></user>
Result
{ "name": "Ana", "address": { "city": "Lisbon" } }

The root element <user> itself is not a key; its children become the top-level properties.

Limitations
Comments and processing instructions are ignored. Namespace prefixes are kept as part of tag names rather than resolved. Mixed text split around child elements is joined into one "#text" value.
Assumptions
The input is a single well-formed XML document.
Privacy
XML is parsed and converted in your browser and is never sent to a server.

Frequently asked questions

Does the conversion keep XML attributes?+

Yes. Attributes become keys with a prefix, @ by default, for example id="5" becomes "@id": "5". You can change the prefix or leave attributes out.

How are repeated elements handled?+

When the same tag appears more than once under one parent, its values are collected into a JSON array. Tick Always use arrays for children to make every child an array.

Is the root element included?+

It isn't: the root element's name is the top-level key of the JSON.

Are numbers converted to JSON numbers?+

Only if you tick Convert numbers & booleans. By default all values stay strings, which avoids losing leading zeros.

Why convert XML to JSON at all?+

JSON is the native data format for JavaScript and most modern APIs, so converting makes XML data easier to inspect, store and use in current applications.

Related tools