JSON to XML

Converts JSON into XML. The two formats do not map cleanly onto each other, so the useful part is knowing which compromises any converter has to make.

Live demo · real result from this tool
Indent

XML

<?xml version="1.0" encoding="UTF-8"?><root>  <name>toolsrift-app</name>  <version>1.4.0</version>  <private>true</private>  <engines>    <node>&gt;=20</node>  </engines>  <scripts>    <dev>astro dev</dev>    <build>astro build</build>  </scripts>  <keywords>tools</keywords>  <keywords>offline</keywords>  <keywords>privacy</keywords></root> 

Processed on your device — nothing is uploaded.

How to use JSON to XML

  1. Paste your JSON.
  2. Copy the XML output.
  3. Check the root element name and any renamed keys against what the receiving system expects.
  4. A root element is invented because XML requires one and JSON does not supply it.
  5. Keys that are not valid XML element names must be escaped or renamed.
  6. Type information is lost — everything becomes text.

XML needs things JSON does not have

Every XML document requires exactly one root element, and a JSON array has no name for one — so a converter invents something like <root> or <item>. XML element names cannot start with a digit or contain spaces, which JSON keys frequently do, so those keys must be escaped or renamed. And XML has no native array: repeated elements imply a list, which means an array of one item is indistinguishable from a single value once converted.

Types disappear

JSON distinguishes the number 42 from the string “42”, and true from “true”. XML content is text, so that distinction is lost unless a schema restores it. Anything consuming the output has to know the types independently, which is why XML ecosystems lean so heavily on XSD. If you control both ends, this is manageable; if you are producing XML for someone else’s parser, check what they expect.

Where you still need XML

Legacy enterprise integrations, SOAP services, government and banking interfaces, RSS, and document formats like DOCX and SVG. XML is not fashionable and it is far from dead, and it has genuine advantages JSON lacks: namespaces, attributes, comments, mixed content and mature schema validation. Converting JSON to XML is almost always about meeting a system that requires it rather than choosing it.

Frequently asked questions

How are JSON keys converted to XML?
JSON keys become XML element names. Arrays create repeated elements. The root is wrapped in a container element.
What happens to JSON arrays?
They become repeated elements, which is XML's equivalent. The consequence is that an array containing one item looks identical to a single value, so consuming code needs a schema or prior knowledge to tell them apart.
Can I customize the XML output?
Basic conversion is provided. For custom XML structure, attributes, or namespaces, use specialized conversion libraries.
Why does my XML have an extra root element?
Because XML permits exactly one root and JSON, particularly a top-level array, does not provide a name for it. The converter supplies one; rename it to whatever the receiving system expects.
Can I convert the XML back to JSON?
Approximately. Attributes, namespaces, comments and element order have no JSON equivalent, and types were already lost, so a round trip gives you something structurally similar rather than identical.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close