JSON to XML Converter — Turn JSON Data into Clean XML Online

JSON is the language of APIs and modern apps; XML is still the language of invoices, feeds, document formats and half the enterprise world — so converting between them is a daily chore that should take seconds. This JSON to XML converter takes any JSON value — objects, nested objects, arrays, strings, numbers, booleans and nulls — and produces clean, indented XML with a proper <?xml version="1.0" encoding="UTF-8"?> declaration. Object keys become element names, arrays become repeated sibling elements under the same name, and special characters in your text (&, <, >, quotes) are escaped properly so the output stays well-formed. You choose the root element name. The conversion rules are deterministic and explained below, the work happens entirely in your browser with no upload, and the sample button loads a two-book catalogue you can watch turn into XML the moment the page opens.

How JSON maps to XML here

The rules are simple and predictable. An object becomes nested elements: {"book": {"title": "Dune"}} becomes a <book> element containing a <title>Dune</title>. An array becomes repeated elements with the same tag: a list of two books under the key “book” produces two sibling <book> elements — the way XML naturally represents collections. Numbers and booleans are written as their plain text form (9.99, true). A JSON null becomes an empty element, <key/>, since XML has no null literal. Keys that are not legal XML names — starting with a digit, or containing spaces — are made safe by replacing invalid characters with underscores and prefixing an underscore when needed, so the output always parses. If the top level is an array, its items are wrapped as <item> elements inside your chosen root.

Worked example

The preloaded sample is a small bookstore: one object holding an array of two books, each with a title, author and price, plus an “open” flag set to true. Converted, you get a <root> document (rename it to “bookstore” using the root field and convert again — the field exists precisely for this) with a <bookstore> element inside, two <book> siblings, and each field as a child element. Paste that output into any XML validator or into the XML to CSV converter on this site and it reads straight back — that round-trip is the honest test of any converter, and this one passes it by construction: every tag it opens, it closes, and every text value is escaped before it is written.

What this converter does not do

JSON has no attributes, so this tool produces elements only — it will not invent attributes from your keys, and if your target XML format needs data in attributes (many SOAP and config formats do), you will need to reshape the JSON or post-edit the XML. Mixed content (text interleaved with elements) also cannot be expressed from JSON, because JSON has no way to write it. Mixed namespaces and XML comments have the same problem. These are properties of the two formats, not defects of the tool — XML is simply the richer document format, and a one-way structural conversion is the honest scope. Within that scope — data-shaped JSON into data-shaped XML — the output is complete and valid.

Frequently asked questions

How are JSON arrays converted?

As repeated elements with the same name: "book": [a, b] becomes two <book> elements. Top-level arrays use <item> for each entry, wrapped in your root element.

What happens to special characters in strings?

They are escaped: & becomes &amp;, < becomes &lt;, and so on — so a title like “Fish & Chips” stays valid XML text and reads back exactly.

Can I choose the root element name?

Yes — the root name field feeds straight into the output. Invalid characters in it are sanitised the same way as keys, so the document stays well-formed.

Is my JSON uploaded anywhere?

No. JSON.parse and the XML writer both run as JavaScript in your browser tab; nothing leaves the page, and the download is generated locally too.

Related tools

Versión en español: Conversor de JSON a XML — Convierte Datos JSON en XML Limpio Online. You may also like: XML to CSV Converter — Flatten XML Files into Spreadsheet Rows · CSV to XML Converter — Turn Spreadsheet Rows into XML Nodes.


Embed this tool on your website — free

Copy the code below to add this working tool to your own page. A small credit link stays with it — that’s all we ask.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top