Skip to content
toolgrid

No tool found. Try another word.

XML to JSON Converter

Convert XML to JSON: elements become keys, repeated elements become arrays, attributes get an "@" prefix. Optionally detect numbers and booleans.

Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.

How to use the XML to JSON Converter

  1. 1 Paste your XML.
  2. 2 Choose the indentation and whether "42" and "true" should become a number and a boolean.
  3. 3 Copy the JSON or download it.

About the XML to JSON Converter

XML is still common in feeds, SOAP services, office files and older APIs, while most modern code works with JSON. The converter reads your XML with the browser's standards-compliant parser and builds a JSON object with the root element as the top key.

Each child element becomes a property. When an element name occurs more than once, its values are collected in an array. Attributes are stored with an "@" prefix and text next to child elements as "#text", so no information is lost and our JSON to XML converter can turn it back. An element with only text becomes a plain string.

XML has no data types: everything is text. With "detect numbers and booleans" values that look like numbers or true/false are converted, which is convenient but can turn identifiers such as postal codes with leading zeros into numbers; leave it off when in doubt.

Frequently asked questions

Why is an element sometimes an array and sometimes not?

An element becomes an array only when it occurs more than once in the same parent. If your code needs a stable shape, check with Array.isArray or wrap single values in an array.

What happens to namespaces?

Element and attribute names keep their prefix (for example "soap:Body"), and xmlns declarations appear as attributes.

Are comments and processing instructions kept?

No. Comments, the XML declaration and processing instructions don't carry data and are left out. CDATA sections are kept as text.

Why does my XML give an error?

XML is strict: every tag must be closed, attribute values need quotes, there must be one root element and & must be written as &. The message shows where the parser stopped.