🔀 JSON to XML Converter

Convert JSON to XML, or XML back to JSON. Arrays become repeated sibling elements; object keys become element tags.

The mapping in both directions

Going to XML, the first key of the top-level object becomes the root element, every other key becomes a child tag, and an array becomes repeated siblings sharing one tag name. The sample converts to:

<?xml version="1.0" encoding="UTF-8"?>
<person>
  <name>Alice</name>
  <age>30</age>
  <tags>admin</tags>
  <tags>user</tags>
</person>

Coming back the other way, an element with children becomes an object, a leaf becomes its text, and a tag that appears more than once becomes an array. Feed the XML above back in and age returns as the string "30" - XML has no number type to restore.

Two shapes that will surprise you

Element names come straight from your keys, and nothing validates them: a key with a space or a leading digit produces XML no parser will accept. Both conversions run in the page, so nothing you paste is uploaded.

Frequently asked questions

Why did some of my JSON disappear in the XML?

An XML document can have only one root element, and this converter takes the first top-level key as that root. Anything beside it is discarded, so nest everything under one key - for example wrap the object in {"root": ...} - before converting.

Why are numbers and booleans strings after converting XML to JSON?

Because XML text is untyped. <age>30</age> carries no clue that 30 was a number, so it comes back as "30". A JSON to XML to JSON round trip is lossy for types, and for single-element arrays, which return as a plain value.

Does it convert XML attributes into JSON keys?

No. Conventions such as prefixing attribute names with @ are not implemented; attributes are simply skipped. If your XML puts data in attributes rather than elements, use a library such as fast-xml-parser instead.