Skip to content

Convert XML to JSON

This tool converts an XML document to JSON in your browser, so that an API payload or a config file becomes something a script can read directly. The root element becomes the one key of the result, an attribute becomes an @-prefixed key, and text next to attributes or child elements goes under #text. A name that repeats among its siblings becomes an array, so the same element can be an object in one file and an array in another; comments are left out, and every value stays exactly the string the document holds, leading zeros included. Your file is never uploaded.

Runs in your browser

Drop a file here

XML, up to 50 MB

How it works

  1. 1 Choose an XML file.
  2. 2 Set the indent between 0 and 8 spaces. 2 is the default, 0 minifies.
  3. 3 GRID16 parses the document and applies the mapping in your browser.
  4. 4 Download the JSON.

Questions

How does an XML element become JSON?
An element with no attributes and no child elements becomes its text as a plain string. An element with either becomes an object: its attributes as @name keys, its child elements under their own names, and any text under #text.
What happens to repeated elements?
A name that occurs once among its siblings stays a single value; a name that occurs more than once becomes an array, in the order the elements appeared. The same element can therefore be an object in one file and an array in another.
Are numbers and booleans converted?
No. XML has no types without a schema, so every value stays exactly the string the document holds; a postal code keeps its leading zero, and a version such as 1.10 stays 1.10 instead of becoming 1.1.
What about namespace prefixes?
They are kept as written, soap:Envelope and @xmlns:soap included. This tool does not resolve a prefix to its namespace URI.
What happens with invalid XML or a DOCTYPE?
The job stops and says why. A document with a DOCTYPE or an ENTITY declaration is refused before parsing, and XML that does not parse, such as a missing closing tag or an unquoted attribute value, is reported with the parser's own message.
Is my file uploaded to a server?
No. The conversion happens in your browser; the file never leaves your device.

More tools