DataSwap Fast file & data format converters, no signup

JSON to XML Converter

Paste JSON below and get well-formed XML back instantly — built with the browser's own DOM APIs (createElement, appendChild, XMLSerializer), not string concatenation, so special characters are escaped automatically. Nothing you paste ever leaves your browser.

Build XML with the DOM's own element APIs, not string concatenation

This tool never assembles XML by gluing strings together — instead it calls document.implementation.createDocument() to build a real XML Document, then createElement and appendChild to grow it, then hands the finished tree to new XMLSerializer().serializeToString(doc). That matters because text content assigned through el.textContent gets escaped automatically and correctly by the browser — an & in your data becomes &amp; in the output without this tool having to remember to do that itself. Object keys become child element tag names. Array values never get a wrapper element: each item repeats the array's own key as a sibling — a "tags" array with two entries produces two sibling <tags> elements, not one <tags> containing a list. Primitive values (strings, numbers, booleans) become the element's text content, and everything is wrapped in one root element you can name yourself.

Worked example

Input: {"person":{"name":"O'Brien & Co.","tags":["a","b"]}} — an apostrophe and an ampersand in a name, and a two-item array. Converting produces:

<root>
  <person>
    <name>O'Brien &amp; Co.</name>
    <tags>a</tags>
    <tags>b</tags>
  </person>
</root>

Notice the & became &amp; automatically — that's XMLSerializer doing its job, not a hand-written replace rule — and tags produced two sibling elements instead of one element collapsing both values into a single line. Now try a key that can't be a tag name, like {"1st place": "gold"} — instead of emitting broken XML, this tool tells you exactly which key failed and why. Need to go the other direction? The XML to JSON Converter parses real XML back into JSON using the browser's own DOMParser.

Frequently asked questions

How does a JSON array become XML? Do I get a wrapper element?

No wrapper — each array item becomes its own sibling element repeating the array's own key. {"tag":["math","computing"]} becomes <tag>math</tag><tag>computing</tag>, not a <tag> element containing two children. This mirrors XML the way it's actually written in the wild: repeated sibling elements, not a single element wrapping a list. A bare top-level JSON array (no object, no key) falls back to the element name "item" for each entry, since there's no key to repeat at the top level.

What if one of my JSON keys isn't a valid XML element name?

It's rejected with a clear message instead of silently producing broken XML. Element names must start with a letter or underscore and contain only letters, numbers, underscores, hyphens, and periods — no leading digit, no spaces, no colons. A key like "1st place" or "full name" fails that check immediately, before any element is built, and the error message names the exact key that failed.

Can I change the root element's name?

Yes — the "Root element" field above the input controls it, and defaults to "root" if you clear it. It goes through the exact same validity check as every other key, so an invalid root name is rejected the same way an invalid object key would be.

What happens with null values, empty objects, and empty arrays?

A null value becomes an empty element — <middleName/> rather than a literal string like "null". An empty object {} also becomes an empty element, since it has no keys to turn into children. An empty array [] produces no element at all for that key, because there are zero items to repeat — this is the direct consequence of arrays not getting a wrapper element.

Is my JSON uploaded anywhere?

No. The XML is built entirely in your browser using the DOM's own document.implementation.createDocument(), createElement, and XMLSerializer — nothing you paste is sent to a server, stored, or logged. That's true for every tool on this site.