XML to JSON

Paste XML and get JSON you can use in code. Attributes become keys starting with @, repeated elements become arrays and the text of an element becomes its value.

Free and private. Everything runs in your browser, nothing is uploaded.

How it works

  1. Paste or open a filePaste your data into the input box or open a file. Sample shows an example.
  2. Check the resultThe converted data appears on the right as you type. Errors show the line and column.
  3. Copy, download or swapCopy the result, save it as a file, or press Swap to convert it back.

How XML is mapped to JSON

The root element becomes the only key of the result. An element that only contains text becomes a simple value, so <name>Alex</name> turns into "name": "Alex". Attributes are written with a prefix, @id by default, and when an element has both attributes and text, the text is stored under #text. Elements with the same name next to each other become an array. CDATA sections are read as text, comments and processing instructions are left out.

With number and boolean detection on, values like 89.90 and true become real JSON types. Codes with a leading zero, such as barcodes or postal codes, and numbers longer than 15 digits stay text, so nothing is lost. Note that an element that appears once is not an array; if your code always expects a list, check for that case.

About XML

XML (Extensible Markup Language) stores data in nested elements with opening and closing tags, and can add attributes to each element. It is common in feeds, e-invoices, Office files and SOAP services.

About JSON

JSON (JavaScript Object Notation) writes data as objects in curly braces, lists in square brackets, text in double quotes, numbers, true, false and null. Almost every API and programming language reads it.

Frequently asked questions

Are external entities or DTDs loaded?

No. The XML is read by your browser's built in parser, which does not load external files. Nothing is sent over the network.

Is my data uploaded?

No. The conversion runs in your browser. Configuration files with passwords or keys never leave your device.

Why is yes still text in my JSON?

In YAML 1.2, the current version, only true and false are booleans. Older YAML 1.1 tools also read yes, no, on and off as booleans. Turn on the YAML 1.1 option if your file was written for such a tool.

What happens with several YAML documents?

If the input has more than one document, each starting with a line of three hyphens, the JSON result is a list with one item per document.

How are XML attributes shown in JSON?

Attributes get an @ in front of their name, for example @id. If an element has attributes and text, the text goes into #text. You can choose another prefix for attributes.

Does it work offline?

Yes. After you open the page once, it keeps working without an internet connection.