JSON to XML
This free JSON to XML converter turns JSON into XML entirely in your browser. Paste your data or upload a .json file, review the result, and download it. Nothing leaves your device, and there is no sign-up.
Going this direction is not simply the previous conversion run backwards. JSON does not record which keys started life as attributes, a namespace URI is often already gone, and plenty of JSON keys are not legal XML names at all. This page states how it handles each of those, and lets you set every one of them yourself.
How to use this JSON to XML converter
- Paste JSON into the box, upload a
.jsonor.txtfile, or drag a file onto the drop area. - Check the Root element name. If your JSON has a single top-level key, that key is used automatically; type over the field to use your own name.
- Pick how attributes and arrays are written: Attribute prefix, Arrays, Namespaces, Indent.
- Click Convert to XML (or wait — it converts as you type), then Copy XML or Download .xml.
- If the JSON is invalid, the error names the line and column where it broke.
Conversion rules — exactly what this page does
Root element
Every XML document needs exactly one root. If your JSON is an object with a single top-level key, that key becomes the root element name. Otherwise — an array at the top level, or an object with several keys — the name in the Root element field is used, which defaults to root. Type any name you like into the field and it wins.
A top-level array has no name of its own, so each item is written as an <item> element inside the root: [1,2] becomes <root><item>1</item><item>2</item></root>.
Attributes
A key is written as an attribute when it starts with the chosen prefix — @ by default, so "@id": "b1" becomes id="b1". Switch the prefix to _ if your JSON uses that. Choose None and no key is treated as an attribute; every key becomes a child element. There is no way to detect attributes without a prefix, because JSON does not mark them — that is stated rather than guessed.
Arrays — repeated elements
- Repeated elements (default) — an array produces one element per item, all with the same name:
"author": ["Alice","Bob"]becomes<author>Alice</author><author>Bob</author>. - Wrap each item in <item> — the array's key becomes a wrapper and each item sits inside an
<item>:<author><item>Alice</item><item>Bob</item></author>. Use this when a fixed shape matters more than compactness. - An empty array produces a single self-closing element.
Note the consequence: with repeated elements, a one-item array and a plain value produce identical XML. That is inherent — XML has no array type — so if the difference matters downstream, use the wrapper mode.
Text, numbers and empty values
- An object's
#textkey becomes the element's text content; its other keys become attributes and child elements. So{"@sku":"007","#text":"Widget"}becomes<item sku="007">Widget</item>. - Numbers are written as-is (
19.99), andtrue/falseas the wordstrueandfalse. nulland the empty string both become a self-closing element —<stock/>. XML cannot tell the two apart, and this page does not pretend otherwise.
Escaping
Text is escaped as &, < and >; attribute values additionally escape ". Newlines and tabs inside an attribute value are written as and 	, because XML would otherwise normalise them to a single space when the file is read back. Tick CDATA for & < to wrap text containing & or < in a CDATA section instead.
Namespaces — the mirror of the XML to JSON page
- Declare from key (default) — a key written
{http://example.com/doc}bookis split into its URI and local name; each distinct URI is given a prefixns1,ns2… and declared on the root asxmlns:ns1="http://example.com/doc", with the element writtenns1:book. This round-trips the Full URI keys mode of the XML to JSON converter exactly. - A key written with a bare prefix,
d:book, keeps its prefix and is declared asxmlns:d="urn:d". The original URI is not recoverable from a bare prefix — the keep prefixes mode upstream drops it — so a synthetic URN is used and the key round-trips asd:bookagain. - None — prefixes and URIs are stripped and only the local name is written. Safest for documents that have no namespaces, and it never produces an undeclared prefix.
Illegal XML names
JSON allows key names that XML forbids — 1st, unit price, a/b, an empty string. Those are sanitised: forbidden characters become _, and a name that does not start with a letter or underscore gets one prepended. The count of renamed keys is shown under the result, so a silent rewrite never happens.
What this tool supports
- Input — pasted JSON, or
.json/.txtfiles by drag-and-drop or file picker. - Shapes — nested objects, arrays of objects, arrays of scalars, top-level objects, top-level arrays and top-level scalars.
- Output — indented with two spaces or minified, with or without the
<?xml version="1.0" encoding="UTF-8"?>declaration.
Limits — read this before pasting something huge
- There is no fixed size limit; the ceiling is your device's memory, because the whole document is built in your browser.
- Above roughly 8 MB of input the tool warns you that browsers commonly struggle there. It still tries — it never silently truncates.
- Very deep nesting produces deeply indented output; extremely deep structures are limited by your browser, not by this page. If it fails, the error is shown rather than a partial result.
- Information that JSON does not carry cannot be invented: attribute-vs-element without a prefix, the original namespace URI behind a bare prefix, and the difference between
nulland"". Each is handled by an explicit rule above.
Privacy
Uploaded files are read with the browser's own file reader and never leave your device. There is no upload endpoint on this page, no account, and no stored history. You can disconnect from the internet after the page loads and it will still work.
FAQ
Is this JSON to XML converter free?
Yes. It is free with no login and no usage limit, and all processing stays in your browser. For the opposite direction see the XML to JSON converter; other formats are handled by the JSON to CSV converter, the CSV to JSON converter, the JSON to Excel converter and the CSV to Excel converter.
Do I have to upload my JSON file?
No. The file is read locally with the browser's file API and converted in the page. Nothing is uploaded, logged or stored.
Can I choose the root element name?
Yes. If your JSON has one top-level key, that key is used automatically; otherwise the Root element field decides, and it defaults to root. Anything you type in the field wins.
How do I turn an array into repeated XML elements?
Leave Arrays on Repeated elements, the default: each array item becomes a sibling element with the array's name. Switch to Wrap each item in <item> if you prefer a wrapper element around the items.
How do I make a key an attribute instead of an element?
Prefix the key with @ — "@id" becomes id="…". You can switch the prefix to _, or turn attribute detection off entirely, in which case every key becomes an element.
What happens to namespaces?
Write keys as {http://example.com/doc}book and the converter declares xmlns:ns1 on the root and writes ns1:book. A bare prefix like d:book keeps the prefix and is declared against urn:d, because the original URI is not recoverable from a prefix alone. Choose None to strip namespaces entirely.
Why did some of my key names change?
They were not legal XML names — starting with a digit, containing a space or a slash, and so on. Illegal characters are replaced with _ and the count is shown under the result, so you can see exactly how many were rewritten.
Does the output include the XML declaration?
Yes by default: <?xml version="1.0" encoding="UTF-8"?> on the first line. Untick XML declaration for a bare fragment.
Can I convert XML back to JSON?
Yes — use the XML to JSON converter. The two pages use mirrored rules, so a document converted one way comes back the other way with its attributes, arrays and namespace keys intact.
Is there a file size limit?
No fixed one — the limit is your device's memory. Input above roughly 8 MB triggers a warning because browsers commonly struggle there, but the conversion is still attempted and any failure is reported instead of returning a partial result.