XML to JSON Converter

Convert XML to JSON with attributes kept under a prefix, repeated elements as arrays, optional number/boolean parsing and clear syntax errors. Free, in-browser.

Runs entirely in your browser. Your data is never uploaded.

Related Tools

View All

What is XML to JSON?

Paste XML and get an equivalent JSON object. Element names become keys, repeated elements become arrays, attributes are kept with a configurable prefix and mixed text is stored under #text. Invalid XML is reported with line and column.

How to use XML to JSON

  1. Paste XML into the XML input box, or use Load sample or Open file.
  2. Adjust Attribute key prefix, Ignore attributes, Convert numbers and booleans and Always use arrays for elements as needed.
  3. Pick the JSON Indentation.
  4. The JSON output updates as you type; use Copy or Download.

Example

Input
<book id="7"><title>Dune</title><price>9.5</price></book>
Output
{
  "book": {
    "title": "Dune",
    "price": 9.5,
    "@_id": 7
  }
}

When to use XML to JSON

Use it to inspect or migrate XML data (feeds, SOAP responses, config files) into JSON-based tools. Comments, namespaces declarations and element order relative to text are not preserved exactly, so it is not suitable for round-tripping documents like XHTML.

How XML to JSON works

The document is first validated with fast-xml-parser's XMLValidator, which reports the first syntax error with its position. It is then parsed with XMLParser: the XML declaration and processing instructions are dropped, values are trimmed, and – when type conversion is on – numeric and boolean text such as 9.5 or true becomes a JSON number or boolean. With Always use arrays every element is wrapped in an array so the structure is stable regardless of how many children appear.

Common Use Cases

  • Inspect a SOAP or RSS response as JSON
  • Migrate XML configuration to a JSON format
  • Load XML exports into JavaScript code
  • Compare two XML documents by converting them to JSON

FAQs

Why is a single element an object but two elements an array?

By default the parser only creates arrays when an element repeats. Enable Always use arrays for elements for a predictable shape.

Why did "007" become 7?

Type conversion turns numeric text into numbers. Turn off Convert numbers and booleans to keep all values as strings.

Where do attributes go?

They are stored on the element's object with the prefix, for example "@_id": 7. Enable Ignore attributes to drop them.

Good next steps

Explore more categories