XML

XML to JSON Converter

Converts an XML document to JSON, stating plainly which shape decisions it made and why they matter.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the XML you want converted.
  2. Decide how attributes should appear, and whether repeated elements should always become arrays.
  3. Turn on type conversion only if you are sure no identifier in the document merely looks like a number.
  4. Select Convert to JSON, then check one record against the original before trusting the whole file.

What xml to json does

XML and JSON do not describe the same kind of thing, so every converter has to make choices no standard settles. XML distinguishes attributes from child elements and JSON has only keys, so attributes are given an "@" prefix here. XML lets an element hold both text and children, so that text becomes a "#text" key. And XML has no array: three <tag> siblings are just three elements.

That last one is the trap worth knowing about. Repeated siblings become a JSON array, but an element that happens to appear once becomes a single value rather than a one-item array — so two documents of the same type convert to two different shapes when one of them has a single item. Anything reading the result then has to handle both. Switch on "always use arrays" if the consumer is code rather than a person.

Frequently asked questions

Because XML has no array. Repeated siblings look like a list and are converted to one, but a single element is indistinguishable from a list of one. That means two documents of the same type can convert to different shapes. If code is reading the output, set repeated elements to "always an array" so the shape is stable.

It marks a value that was an XML attribute rather than a child element. JSON has only keys, so without a marker an attribute and a child element with the same name would collide. You can switch the prefix off, but then that collision is possible.

Only if you know the document well. Everything in XML is text, so the converter has to guess, and it will happily turn a postcode of 0800 into the number 800 or an account reference of 1.10 into 1.1. Leave it off when identifiers are involved.