Convert JSON into well-formed XML in your browser. Choose the root element name, include or omit the XML declaration, and pick 2 spaces, 4 spaces or no indentation.
Map a JSON tree onto elements, safely. Paste JSON and get well-formed XML back. Arrays become repeated elements, invalid key names are coerced into legal element names, and the declaration and indentation are both up to you.
XML output
Mapping JSON onto XML without losing your mind
The two models do not line up
JSON has six value types — object, array, string, number, boolean and null — and every one of them is self-describing. XML has exactly one primitive: text. Everything else is structure built from elements and attributes. There is no official mapping between the two, which is why every converter you meet behaves a little differently.
The convention used here is the most common and the most predictable one. An object becomes an element whose children are its keys. A string, number or boolean becomes an element containing its text form. null becomes an empty element. That leaves arrays, which have no XML counterpart at all: the standard workaround is to repeat the parent element once per item, so {"item": [1, 2]} becomes <item>1</item><item>2</item> rather than inventing a wrapper element the receiving schema will not expect.
Not every JSON key is a legal element name
XML element names follow the NCName production: they start with a letter or underscore, then allow letters, digits, hyphens, periods and underscores. No spaces, no slashes, no leading digit, and nothing beginning with the letters xml in any casing, which the spec reserves.
JSON keys have no such restriction — they are arbitrary strings, and real-world payloads are full of "user name", "2024" and "@type". Emitting those verbatim produces a document no parser will accept. Invalid characters are therefore replaced with underscores and a leading underscore is added when a name starts with a digit. It is a lossy step, so if the element names matter downstream, rename the keys in the JSON first rather than letting the converter guess.
Declaration, indentation and what is safe to change
The <?xml ... ?> declaration is optional for UTF-8 documents; parsers assume UTF-8 when it is absent. Include it when the file will be written to disk, served over HTTP or handed to a strict enterprise pipeline, and leave it out when the fragment is being embedded inside a larger document, where a second declaration is a fatal error.
Indentation is the subtler choice. Unlike JSON, XML whitespace inside an element is part of the content, so pretty-printing technically changes the document: an element that held Ada now holds a newline, some spaces, Ada, a newline and more spaces. Most schemas ignore this, but signature verification, xml:space="preserve" sections and whitespace-sensitive formats do not. Use indentation while you are reading, and switch to minified output for anything a machine will consume.
FAQ
Is my JSON uploaded anywhere?
No. The document is parsed and serialised entirely in your browser using the built-in JSON functions, so nothing is sent to a server.
How are JSON arrays represented?
By repeating the parent element once per item. {"item": [1, 2]} becomes <item>1</item><item>2</item>, which is the convention most XML schemas expect.
What happens to keys that are not valid element names?
Illegal characters become underscores and a leading underscore is added if the name starts with a digit. Rename the keys first if the exact names matter.
Why is my output missing the XML declaration?
It is optional and controlled by a checkbox. Parsers default to UTF-8 without it, and it must be omitted when the output is embedded inside another document.
Are values written as attributes?
No. Every value becomes element text. Attributes cannot be inferred from plain JSON, so choosing them would require a schema this tool does not have.
Does indentation change the meaning of the document?
Technically yes, because whitespace inside an element is content. Most schemas ignore it, but use minified output for signed or whitespace-sensitive XML.