Skip to content
ZeroServer.tools

JSON to XML

Convert JSON structures into nested XML markup.

or drop a file here
XML Output

How JSON Maps to XML

Each JSON object key becomes an XML element, nested objects become nested elements, and arrays repeat the parent element once per item. Special characters (&, <, >) are escaped, and keys that aren't valid XML element names are sanitized. The whole document is wrapped in a single <root> element. Conversion is instant and fully local.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Producing XML for a legacy integration from a JSON source.
  • Converting an API response for a system that only ingests XML.
  • Generating an XML fixture from a captured payload.
  • Migrating data into an XML-based pipeline.
  • Comparing a JSON structure against an XML schema's expectations.

How it works in practice

A worked example

A payload has to go into a system that only accepts XML, and its keys were never written with XML in mind.

Input
{
  "order id": "AC-4471",
  "2026": true,
  "tags": ["prod", "eu-west"],
  "note": "a < b & c",
  "shipped": null
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <_2026>true</_2026>
  <order_id>AC-4471</order_id>
  <tags>prod</tags>
  <tags>eu-west</tags>
  <note>a &lt; b &amp; c</note>
  <shipped></shipped>
</root>

Four transformations, none of which XML gives you a choice about. The key with a space became an underscore and the one starting with a digit gained a leading underscore, because an element name cannot begin with a digit or contain a space. The array became the same element twice, since XML has no array type and repetition is the only way to express a list. The angle bracket and ampersand were escaped, and the null became an empty element — which is indistinguishable from an empty string once it arrives.

The edge case that catches people

The renaming is where data goes missing, quietly. A space, a colon and a slash all become the same underscore, so three distinct keys can collapse onto one element name and the document that arrives has fewer fields than the one you sent — with nothing reporting it. The array mapping has a matching problem: a list of one item produces output byte-identical to a plain value, so a reader cannot tell them apart and code that expects a list will break on exactly the payloads that have a single entry.

When not to use this tool

When the far end has a schema, which is usually the reason it wanted XML. Real documents carry attributes, namespaces and a declared element order, and a mapping from plain JSON can express none of those — every value here becomes an element, nothing becomes an attribute, and no namespace is ever declared. Generate against the schema with a library that reads it, and use this to see the shape of a payload or to produce a rough first draft that someone then makes conformant.

Frequently Asked Questions

How do JSON arrays map onto XML?
By repeating the parent element once per item: {"tag":["a","b"]} becomes two <tag> elements, not one holding a list, because XML has no array type. A top-level array is wrapped in <root> with each item as <item>, since a document may contain exactly one root element.
Which characters get escaped?
The ampersand first, then < and >, so the ampersands introduced by the later replacements are not escaped a second time. Quotes are deliberately left alone: they only need escaping inside attribute values, and this converter emits no attributes at all.
What happens to keys that are not valid element names?
Anything outside letters, digits, underscore, dot and hyphen becomes an underscore, and a name not starting with a letter or underscore gets one prepended. So "first name" becomes <first_name> and "2024" becomes <_2024> — XML forbids an element name beginning with a digit.
Can the XML be converted back to the original JSON?
Not faithfully. XML text nodes are all strings, so 42, "42" and true become indistinguishable, and a one-item array is indistinguishable from a plain value. Treat this as a one-way transform unless you control the schema on both ends.
Why are there no XML attributes in the output?
Because JSON gives no way to mark which keys are attributes and which are child elements. Making every key an element is the unambiguous choice. Conventions that map an @-prefixed key to an attribute exist in specific libraries but are not part of any standard.

Common errors and gotchas

  • Producing element names from keys that are not valid XML names, such as ones beginning with a digit.
  • Losing the attribute-versus-element distinction, which JSON has no way to express.
  • Converting an array without a wrapping element, which yields repeated siblings a schema may reject.
  • Failing to escape ampersands and angle brackets inside string values.
  • Assuming numbers and booleans stay typed, when XML text content is text.

Related Converters tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate