JSON to XML
Convert JSON to XML with attributes, a custom root and indentation
About JSON to XML
Turns JSON into well-formed XML: keys starting with @ become attributes, #text becomes element text and arrays become repeated elements, with a configurable root name, indentation and optional XML declaration. Keys that aren't valid XML names, such as first name or 2024, are rewritten as first_name and _2024, and empty arrays produce no element. Handy for SOAP requests, legacy imports and XSLT input, all inside your browser.
Category: Converters.
Frequently asked questions
When is the root element name used?
▾
Only when the JSON doesn't provide one. A single-key object like {"catalog": {...}} uses catalog as the root; several keys, a top-level array, a plain value or a single key holding an array are wrapped in the root you choose, and top-level array items become <item> elements.
How are invalid keys turned into XML element names?
▾
Characters that XML names don't allow, including spaces, slashes and #, become underscores, and a name that is empty or starts with a digit, hyphen or period gets a leading underscore. A prefixed key like soap:Body keeps its colon only when a matching @xmlns:soap is declared on that element or an ancestor; otherwise it becomes soap_Body.
How are null, empty arrays and nested arrays written?
▾
null and empty strings become self-closing elements like <note/>, and an empty array produces no element at all. An array inside another array becomes an element wrapping <item> children, and objects used as attribute values are written as JSON text.
Which characters are escaped in the output?
▾
&, <, >, double quotes and apostrophes are escaped in text and attributes, and line breaks and tabs inside attribute values become character references so parsers don't turn them into spaces. Control characters that XML 1.0 can't represent are removed, and an element with both #text and children is written on one line so indentation doesn't change its text.