JSON to XML Converter: Well-Formed XML from Any JSON
Convert JSON to well-formed XML with a root name, attributes, arrays as repeated elements and escaping. Invalid names are renamed with warnings.
Runs in your browser. Nothing is uploaded.
ConvertersJSON to XML
JSON
Max 50MB each
Empty: a single top-level key is the root, else root
For arrays that have no key
Keys starting with it become attributes
Text of an element that also has attributes
Result
Paste JSON on the left, or load the sample. XML appears here as you type.
Example
{"order":{"@id":1001,"customer":"Asif","item":["Pen","Pad"],"note":null}}<?xml version="1.0" encoding="UTF-8"?> <order id="1001"> <customer>Asif</customer> <item>Pen</item> <item>Pad</item> <note/> </order>
How JSON becomes XML
XML needs exactly one root element, and JSON does not, so the root name is a choice. If you leave it empty and your JSON has a single top-level key, that key becomes the root; otherwise the root is called root. You can type any valid name instead. Objects become elements with child elements, and arrays become repeated elements with the same name, so {"item":["Pen","Pad"]} writes two <item> elements. An array with no key of its own, such as a top-level array, uses the array item name you set, item by default.
Attributes come from keys that start with a prefix, @ by default: {"@id":1001} becomes id="1001". When an element has attributes and text, put the text under the text key, #text by default. Numbers, booleans and big integers are written as text, null becomes an empty element or is left out, and you can choose self-closing tags (<a/>) or open and close pairs. Indent with 2 or 4 spaces, a tab, or minify, and add or drop the XML declaration.
Escaping and invalid names
Text and attribute values are escaped, so & < > " and ' are written as entities and a value such as <script> arrives as data, not markup. Line breaks and tabs inside attribute values are written as character references because XML parsers would otherwise normalise them to spaces. Characters that XML 1.0 cannot contain at all, such as most control characters and unpaired emoji halves, are removed, and the tool counts how many.
JSON keys can be anything, but XML names must start with a letter or underscore and contain only letters, digits, hyphens, periods and underscores. A key like first name or 1st is renamed to first_name or _1st, and a warning lists the changes so you can see them. If two keys would end up with the same name, the second gets a numeric suffix so nothing is overwritten. A key named __proto__ is renamed too.
Limits and tips
XML has no number or boolean type, no null, and element order matters, so a round trip through XML cannot be perfectly lossless: numbers return as text unless the XML to JSON tool detects them, and a single-item array comes back as a plain value unless you force arrays. Use the paired tool to check what your data looks like after the trip.
This tool writes elements, attributes and text. It does not generate namespaces, CDATA sections, comments or schemas. Large inputs are converted in a background worker, and nothing is uploaded: the work happens in your browser.
Frequently asked questions
How do I set attributes?
Name keys with the attribute prefix, @ by default. {"@id":1} becomes id="1" on the element. You can change or disable the prefix.
What happens to JSON keys that are not valid XML names?
They are renamed (spaces and symbols become underscores, a leading digit gets an underscore) and a warning lists every change.
How are arrays written?
Each item becomes an element with the key name, so an array under "item" produces repeated <item> elements. Arrays without a key use the item name you choose.
Is the output escaped?
Yes. Ampersands, angle brackets and quotes are escaped in text and attributes, so values cannot inject markup.
Can null be represented?
XML has no null. A null value becomes an empty element, or is left out of objects if you choose that option.
