JSON to XML Converter
Convert JSON to XML in your browser, with no upload and no sign-up.
In-depth guide
JSON to XML: element names, arrays and what the converter cannot express
The exact rules of this converter: a fixed <root>, arrays as <item>, null as an empty tag, no attributes, key sanitising and its collisions, and one known gap with control characters.
Key figures at a glance
- Root element
- Always <root>
- There is no option to rename it and no XML declaration is written.
- Array items
- Each item becomes <item>
- The array's own key becomes the wrapper element.
- Attributes
- Never produced
- Every JSON member becomes a child element, so XML attributes cannot be generated.
- Escaped characters
- & < > " in text
- Apostrophes are left as they are; they need no escaping in element text.
The mapping
Paste JSON and the right-hand box shows indented XML (two spaces per level). Nothing is uploaded. The rules, taken from the converter's code and run against sample input:
| JSON | XML |
|---|---|
object {"a":1} |
<root><a>1</a></root> (children indented on separate lines) |
array [1,2] |
<root><item>1</item><item>2</item></root> |
nested array under key tags |
<tags><item>a</item><item>b</item></tags> |
null |
self-closing <none/> |
{} (empty object) |
self-closing <obj/> |
[] (empty array) |
an element whose body is a blank line |
"" (empty string) |
<s></s> |
true, 1.50 |
<t>true</t>, <n>1.5</n> (numbers print as JavaScript does) |
bare value 5 |
<root>5</root> |
null at top level |
<root/> |
Example: [{"name":"Mei","city":"Singapore","age":30},{"name":"Ali","city":"Johor","age":25}] becomes
<root>
<item>
<name>Mei</name>
<city>Singapore</city>
<age>30</age>
</item>
<item>
<name>Ali</name>
<city>Johor</city>
<age>25</age>
</item>
</root>
There is no <?xml ... ?> declaration, and the page does not choose an encoding; copy or download (converted.xml) the text and add a declaration yourself if the consumer requires one.
Element names are sanitised
XML names are stricter than JSON keys: they cannot start with a digit and cannot contain spaces. The converter replaces every character outside A–Z a–z 0–9 _ . - with _, and prefixes _ if the result does not start with a letter or underscore:
| JSON key | Element |
|---|---|
first name |
<first_name> |
1st |
<_1st> |
@id, #text |
<_id>, <_text> |
a:b |
<a_b> |
x.y-z |
<x.y-z> (unchanged) |
名字 |
<__> (non-ASCII letters are replaced, although XML allows many) |
empty key "" |
<_> |
Two consequences matter. Different keys can collide: a b, a:b and a_b all become <a_b>, and XML does not forbid repeated elements, so no data is lost but the distinction is. And keys written in non-Latin scripts turn into underscores, which makes the XML unreadable for those documents. If your data uses such keys, rename them before converting.
Text is escaped, but not validated
&, <, > and " in values become &, <, > and ", so Mei & Co <x> is safe. Line breaks and tabs inside strings are copied literally. One gap: control characters other than tab, line feed and carriage return are copied unchanged, but XML 1.0 forbids them (legal characters start at U+0020 except tab, line feed and carriage return), so a JSON string such as "\u0001" yields output that an XML parser will reject. Strip such characters beforehand.
What cannot be expressed
- Attributes: everything becomes an element. To get
<person id="1">, build the XML another way. - Round trips: JSON → XML → JSON turns every array into repeated
itemchildren and every scalar into a string. The XML to JSON converter reads attributes as@name, but this converter writes@nameas<_name>. - Types:
5,"5"andtrueall appear as plain text. A consumer needs a schema to know which is which. - Fixed root: if the target expects a particular document element, rename
<root>in the output. - Mixed content has no JSON counterpart here.
Tip: For data feeds, wrap your values in a one-key object first, for example
{"orders":[…]}; the result is<root><orders><item>…, which is closer to what most XML schemas expect than a bare<root><item>.
Common mistakes
- Expecting attributes or a custom root name.
- Using keys with spaces or punctuation and not noticing they were rewritten.
- Pasting output into a system that demands an XML declaration or a schema.
- Assuming an empty array gives an empty tag; it gives an element with a blank line inside.
Related tools
Convert back with XML to JSON, check the source with the JSON validator, view paths with JSON to text, or produce a table with JSON to CSV.
Frequently asked questions
Is my data uploaded anywhere?
No. The conversion runs entirely in your browser using JavaScript. Nothing you paste leaves your device, is logged, or is stored on a server.
How large a document can it handle?
The limit is your browser's memory rather than any server quota. Documents of a few megabytes convert without trouble; very large files may make the page briefly unresponsive while it works.
What happens to nested data?
Formats that have no concept of nesting store nested values as a JSON string inside the cell, so nothing is silently discarded and the structure can be recovered.
Does it handle quotes and commas inside fields?
Yes. Parsing follows RFC 4180, so quoted fields containing commas, escaped double quotes, and line breaks inside a field are all read and written correctly.
Sources
- W3C — Extensible Markup Language (XML) 1.0, Fifth Edition — Names (section 2.3), legal characters (section 2.2), escaping and well-formedness.
- IETF — RFC 8259, The JSON Data Interchange Format — The JSON input.
This guide explains published rules in plain language. It is not financial, legal or official advice — rules change, so confirm with the agency linked above before you commit.
Related tools
Embed this tool on your website
Free to use. Paste this code into your page and keep the link back to ToolSG.