Skip to content
1001 Tools
sr
Developer tools

JSON to XML Converter

Paste JSON and get well-formed, indented XML back. Objects turn into nested elements named after their keys, arrays become repeated elements, and primitives become text. You can set the root element name, and everything runs in your browser — the JSON is never uploaded.

XML output

How it works

The JSON is parsed and walked recursively. Each object property becomes a child element named after its key; nested objects nest their elements; and an array produces the same element repeated once per item, which is the standard way to represent lists in XML. Values are converted to text and XML-escaped, so characters like &, < and " are turned into their entities and the output stays valid.

Because XML element names are stricter than JSON keys, keys are sanitised: characters that are not letters, digits, hyphens, underscores or dots are replaced with underscores, and a leading underscore is added if a name would start with a digit. A JSON document whose top level is an array is wrapped in the root element with <item> children, so the result always has exactly one root element as XML requires. Attributes are not generated — every value is expressed as an element, which is unambiguous and round-trips cleanly.

Practical examples

A config object

{"server":{"host":"localhost","port":8080}} becomes a <root> with a nested <server> containing <host> and <port> elements — ready to drop into an XML config.

A list of records

An array like [{"id":1},{"id":2}] is wrapped as <root> with two <item> children, each holding an <id>, giving valid XML with a single root.

Renaming the root

Set the root name to “catalog” and {"book":"…"} becomes <catalog><book>…</book></catalog> instead of the default <root> wrapper.

Frequently asked questions

How are JSON arrays represented in XML?

As repeated elements. An array under the key “tag” becomes several <tag> elements, one per item — the conventional XML way to express a list, since XML has no dedicated array type.

What happens to a top-level array?

It is wrapped inside the root element with each item as an <item> child. XML requires exactly one root element, so a bare list cannot be represented without a wrapper.

Why were some of my keys changed?

XML element names cannot contain spaces or most symbols and cannot start with a digit. Invalid characters are replaced with underscores and a leading underscore is added where needed, so the output is always well-formed.

Does it create attributes or only elements?

Only elements. Representing every value as an element is unambiguous and avoids guessing which fields should be attributes. If you need attributes, you will need to post-process the output.

Are special characters escaped?

Yes. Ampersands, angle brackets and double quotes in values are converted to XML entities (&amp;, &lt;, &gt;, &quot;) so the XML remains valid.

How are null and empty objects handled?

A null value, an empty object and an empty array all become a self-closing element like <key/>, which is the compact, valid way to represent “no content”.

Is the output indented?

Yes, with two spaces per level, so it is easy to read. If you need it compact, you can run the result through an XML minifier or remove the whitespace yourself.

Can it convert XML back to JSON?

Not this tool — it only goes JSON to XML. XML-to-JSON is a separate conversion with its own ambiguities (attributes, mixed content) and would need a dedicated tool.

Is my data uploaded?

No. The conversion runs entirely in your browser with JavaScript. Nothing is sent to a server, and it works offline once the page has loaded.

Related tools