JSON to XML Converter

Convert JSON objects and arrays into well-formed XML.

Free JSON to XML converter that turns JSON objects and arrays into well-formed, indented XML with proper escaping. Runs entirely in your browser — nothing is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How are JSON arrays represented in the XML?

Each array item repeats its parent element name, which is the standard lossless convention — so a "tags" array of ["a","b"] becomes <tags>a</tags><tags>b</tags>. A single <root> element wraps the whole document so the output is always well-formed.

Convert JSON to XML in your browser

Legacy APIs, SOAP payloads and many config formats still expect XML, but modern data is usually JSON. This converter turns any valid JSON object or array into well-formed XML with consistent two-space indentation, so the result is always valid and ready to use.

How it works

The converter walks the JSON and maps each construct to XML:

  • Objects become nested elements, one per key.
  • Arrays repeat their parent element once per item — the standard lossless convention — so "tags": ["a","b"] becomes <tags>a</tags><tags>b</tags>.
  • A single <root> element wraps the whole document so it is always well-formed.
  • Escaping: the &, < and > characters in text are escaped, and property names that aren’t legal XML element names are sanitised.
  • Null has no XML equivalent, so it is emitted as an empty element.

Example

This JSON:

{ "name": "demo", "tags": ["a", "b"] }

becomes:

<root>
  <name>demo</name>
  <tags>a</tags>
  <tags>b</tags>
</root>

The tags array repeated the <tags> element once per item, and <root> wraps the document. The conversion happens entirely in your browser — your data is never uploaded or stored.

A more complete worked example

JSON:

{
  "order": {
    "id": "ORD-001",
    "customer": "Alice",
    "items": [
      { "sku": "W-01", "qty": 2 },
      { "sku": "W-02", "qty": 1 }
    ],
    "shipped": null
  }
}

XML output:

<root>
  <order>
    <id>ORD-001</id>
    <customer>Alice</customer>
    <items>
      <sku>W-01</sku>
      <qty>2</qty>
    </items>
    <items>
      <sku>W-02</sku>
      <qty>1</qty>
    </items>
    <shipped></shipped>
  </order>
</root>

Each items entry repeats the <items> tag; the null value becomes an empty <shipped/> element.

Key XML escaping rules

JSON values can contain characters that are not valid as raw XML content:

CharacterJSONXML escaped form
Ampersand&&amp;
Less-than<&lt;
Greater-than>&gt;
Double quote (in attributes)"&quot;

The converter handles all of these automatically. If your JSON values contain HTML snippets or URLs with ampersands, the output is safe XML.

Element name rules

XML element names cannot start with a digit or contain spaces. If a JSON key violates these rules (for example "1stItem" or "full name"), the converter sanitises it — prepending an underscore for names starting with a digit, and replacing spaces with underscores — so the output is always a well-formed XML document.