JSON to XML
JSON to XML converts JSON data into well-formed XML documents in one click — for legacy SOAP services, enterprise middleware, RSS feeds, and config files that never made the JSON jump.
How to Use
- 1
Paste your JSON into the input panel. (There is no file upload or drag-and-drop — paste the text.)
- 2
Set the root element name — XML requires one parent tag, default is "root".
- 3
Click Convert to XML — the XML appears in the output panel; arrays become repeated sibling elements.
- 4
Copy the result or download it as a .xml file.
Frequently Asked Questions
Why is a root element needed?
How are JSON arrays converted?
What happens to keys with spaces or special characters?
How are null values handled?
Can I produce XML attributes?
How is special text escaped?
Does it support namespaces or CDATA?
Can I convert the XML back to JSON?
What if my JSON is invalid?
Is my data uploaded anywhere?
Generative Answer & AI Documentation
What is the JSON to XML?
The JSON to XML converter turns a JSON document into a well-formed XML document: paste JSON into the input panel, set the root element name (the default is “root”), click “Convert to XML”, and the XML appears in the output panel, ready to copy or download as data.xml. The output always begins with the declaration <?xml version="1.0" encoding="UTF-8"?>, followed by your data wrapped in the root element, indented two spaces per level. Arrays become repeated sibling elements under the parent key — an items array becomes several <items> elements, with no wrapper element and no singularising of the name. Null values and empty objects become self-closing tags such as <score />. Text is escaped the XML way (& becomes &, < becomes <, and so on), and keys that are not valid XML names are sanitised: every character outside letters, digits, underscore, and hyphen becomes an underscore. The conversion runs entirely in your browser — nothing is uploaded, nothing is logged.
Why use JSON to XML offline?
Plenty of systems never made the JSON jump: SOAP web services, enterprise middleware, older config formats, RSS consumers, and import tools that accept XML and nothing else. Feeding one of those systems means producing XML, and writing it by hand from a JSON response is slow, error-prone work — one unescaped ampersand or one mismatched tag and the whole document is rejected. This tool does the mechanical translation in one click, with escaping and structure handled for you. Doing it locally matters too: the JSON being converted is often a real API payload or an internal config, and a server-side converter would receive all of it. Here it never leaves your tab, and the tool works offline once the page has loaded.
When should you use this tool?
Use it when a system on the other end speaks XML and your data is JSON: building a SOAP request body from a JSON object, preparing a config file for a legacy tool, generating an RSS item from structured data, or feeding a data import that expects XML. Set the root element name to whatever the receiver expects — many SOAP operations and import schemas reject a document whose root tag is wrong, and “root” is only a placeholder. Do not use it when the receiver needs XML attributes, namespaces, or CDATA sections: JSON has no syntax for any of those, so this tool cannot produce them, and you would need to add them by hand afterwards. For the reverse trip, the XML to JSON page converts XML back into JSON.
Key Benefits
- Root element control: name the single parent tag the receiver expects instead of accepting a fixed default.
- Declaration included: every output starts with the standard XML declaration, so the document is complete, not a fragment.
- Escaping handled: & < > " and ' in text are escaped automatically, so a value like “Don't forget me” cannot break the document.
- Arrays done right: repeated sibling elements under the parent key, matching how most XML consumers expect lists.
- Key sanitising: spaces and special characters in JSON keys become underscores, so the output is always a valid element name.
- Copy or download: one click copies the XML, another saves it as data.xml.
Common Use Cases
- Building a SOAP request body from a JSON object for a legacy web service.
- Preparing a configuration file for an older tool that reads XML and has no JSON mode.
- Generating RSS feed items from structured post data.
- Feeding a data import or migration tool that expects an XML document.
- Showing a colleague or a student how a JSON structure maps onto XML, element by element.
Developer Notes & Best Practices
The conversion is a small recursive walk, and every rule in it is visible in the output. The root name you type is sanitised the same way keys are — every character outside letters, digits, underscore, and hyphen becomes an underscore — and an empty root name falls back to “root”. The XML declaration is always the same line: <?xml version="1.0" encoding="UTF-8"?>. Each object becomes nested elements named after its keys, indented two spaces per level; each array becomes one element per item, repeated under the parent key, so the three-item list in the example becomes three <items> elements and never an <items> wrapper. A top-level array is the one exception to the naming rule: its items use the literal tag <item>, because there is no parent key to borrow. A null value or an empty object becomes a self-closing tag (<score />), and a string, number, or boolean becomes text inside its element — with no type information kept, so 42 and "42" look identical in the output. Escaping covers all five XML characters: & becomes &, < becomes <, > becomes >, " becomes ", and ' becomes ', even inside plain text — that is why the example's “Don't forget me” shows as Don't. Two sharp edges to know: an empty array under a key produces no element at all — the key simply vanishes from the output — and sanitising can collide, so "user name" and "user_name" both become <user_name>, producing two elements with the same tag. Key order follows the JSON as parsed, except that integer-like keys ("10", "2") are listed first in numeric order, as in every JavaScript JSON parser.
How each JSON value becomes XML
| JSON value | XML output | Note |
|---|---|---|
| { "to": "Tove" } | <to>Tove</to> | Object keys become element names |
| ["Milk", "Bread"] | <items>Milk</items> <items>Bread</items> | Arrays repeat the parent key; no wrapper element |
| [1, 2] (top level) | <item>1</item> <item>2</item> | A top-level array uses the literal tag <item> |
| null | <score /> | Null becomes a self-closing tag |
| {} | <empty /> | An empty object becomes a self-closing tag |
| [] under a key | (no element) | An empty array produces nothing — the key vanishes |
| "user name" | <user_name> | Spaces and invalid characters become underscores |
| "Don't" | Don't | Apostrophes are escaped, even in plain text |
- Set the root element to the name the receiver expects before converting — a SOAP operation or import schema that wants <Envelope> or <order> will reject a document rooted at <root>.
- Read the output once for sanitised keys: a key with spaces becomes underscores, and two keys that sanitise to the same name produce duplicate tags — rename the JSON keys first if that happens.
- Validate the XML against the receiver's schema (or paste it into the XML to JSON page and check the round trip) before sending it to a system that charges for failed imports.
- Keep the JSON original: XML carries no types, so a round trip back to JSON may not restore numbers and booleans exactly as they were.
- For a SOAP service, expect to add the envelope, namespaces, and headers by hand afterwards — this tool produces the body content, not a complete SOAP message.
Common Mistakes
- Expecting an <items> wrapper around a list: arrays become repeated sibling elements (<items>Milk</items><items>Bread</items>), never a wrapper with items inside — that is how most XML consumers expect lists.
- Expecting JSON values to become XML attributes: JSON has no attribute syntax, so every value becomes an element, and a receiver that wants id="284" will not find it.
- Leaving the root element as “root” when the receiver expects a specific tag — a SOAP operation or import schema usually rejects the wrong root name.
- Assuming an empty array will show up in the output: it produces no element at all, so a key with [] vanishes without warning — check the output for missing keys.
- Assuming the round trip preserves types: XML stores everything as text, so a number that goes through XML may come back as a string depending on the parser — keep the JSON original as the source of truth.
- Pasting invalid JSON and wondering why nothing converts: the input is parsed first, and a syntax error fails the conversion before any XML is produced — fix the JSON, then convert.
Limitations
JSON has no syntax for XML attributes, so everything becomes an element — there is no way to mark a value as an attribute, and the tool never invents one. There are no namespaces, no CDATA sections, and no choice of XML declaration: the output is always the UTF-8 version-1.0 declaration. An empty array under a key produces no element at all, so that key disappears silently from the output. Key sanitising can collide: two different keys that sanitise to the same name produce duplicate elements. XML itself carries no type information — numbers, booleans, and strings are all text, so whether 42 comes back as a number depends on the parser at the other end. The root name is sanitised too, so a name with spaces or special characters will not survive as typed. Conversion runs only when you click “Convert to XML”, there is no file upload, and very large documents can be slow in a browser tab.
Structured Input/Output Example
{
"note": {
"to": "Tove",
"from": "Jani",
"heading": "Reminder",
"body": "Don't forget me this weekend!",
"items": ["Milk", "Bread", "Eggs"]
},
}<?xml version="1.0" encoding="UTF-8"?>
<root>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<items>Milk</items>
<items>Bread</items>
<items>Eggs</items>
</note>
</root>Related Tools
XML to JSON
XML to JSON converter: parse XML into clean, readable JSON instantly. Tame SOAP responses, RSS feeds, and legacy configs into data JavaScript can use.
JSON to CSV
JSON to CSV converter: flatten JSON arrays into spreadsheet-ready CSV in seconds. Nested objects become dot-notated columns; output opens cleanly in Excel.
JSON to YAML
JSON to YAML converter: convert JSON to clean, readable YAML instantly. Ideal for Kubernetes, Docker Compose, and CI configs. Free, works offline.