DevToolPal
EN

XML to JSON Converter

Convert XML to JSON in your browser, keeping attributes, text and repeated elements, with exact error locations.

Runs locally, never uploaded

Options

Input

0 chars · 0 B

Output

0 chars · 0 B

What it does

This tool turns an XML document into JSON. Elements become object keys, attributes become keys with a prefix, text inside an element becomes its value, and repeated sibling elements become arrays. Before converting, the XML is validated: if a tag is not closed or an attribute is malformed, you see the exact line and column.

How to use

  1. Paste XML into the Input box, upload or drop an .xml file, or click Sample.
  2. The JSON appears on the right as you type.
  3. Adjust the options:
    • Indent: 2 or 4 spaces, tabs, or minified output.
    • Attribute prefix: the marker for attributes, @ by default. Leave it empty to ignore attributes.
    • Convert numbers and booleans: turn text like 42 and true into real JSON numbers and booleans.
    • Always use arrays: wrap every child element in an array so the structure is predictable.
  4. Copy or download the result as a .json file.

Example

<book id="bk101">
  <title lang="en">XML Developer's Guide</title>
  <tag>xml</tag>
  <tag>programming</tag>
</book>

becomes

{
  "book": {
    "title": { "#text": "XML Developer's Guide", "@lang": "en" },
    "tag": ["xml", "programming"],
    "@id": "bk101"
  }
}

Notes

The XML declaration (<?xml ...?>) and processing instructions are left out of the JSON. Comments are ignored. Whitespace around text is trimmed.

FAQ

› How are XML attributes represented in JSON?

As keys that start with the attribute prefix, "@" by default. For example <price currency="USD">44.95</price> becomes { "@currency": "USD", "#text": "44.95" }. Clear the prefix field to drop attributes entirely.

› Why is an element sometimes an array and sometimes an object?

Repeated elements become arrays, a single element stays a plain value. If your code expects the same shape every time, turn on "Always use arrays".

› Are numbers converted?

Not by default, because values like zip codes or IDs with leading zeros would change. Turn on "Convert numbers and booleans" to get 42 instead of "42" and true instead of "true".

› Is my XML uploaded?

No. Parsing happens in your browser.