How to use it
- Choose a JSON file, drop it on the box, or paste JSON; the result appears at once.
- Set the root element name, the name for items of nested lists, the indentation and whether the XML declaration is added.
- Read the notes next to the result: they list renamed keys and other changes.
- Download the .xml file or copy the result.
Rules and limits
XML and JSON mapping
- Each element becomes a key with the element’s name. Namespace prefixes stay part of the name:
soap:Body. - Attributes become keys with an “@” in front:
id="7"becomes"@id": "7". Namespace declarations are kept the same way, as"@xmlns:soap". - An element with only text becomes that text. If it also has attributes or child elements, its text goes under
"#text":<price currency="EUR">12.50</price>becomes{"price": {"@currency": "EUR", "#text": "12.50"}}. - Elements that repeat under the same parent become an array, in document order. Interleaved names are grouped, so the order between different names is not kept.
- CDATA sections become ordinary text. Comments, processing instructions and the DOCTYPE are dropped. Entities defined only in an external DTD, such as
in XHTML, are kept as written, with a note. - An empty element such as
<note/>becomes"". Whitespace between elements is dropped and text is trimmed, except insidexml:space="preserve". - All values stay strings, because XML has no data types:
"00123"keeps its leading zeros.
From JSON to XML
- An object with exactly one key (whose value is not an array) gives the root element. Anything else is wrapped in the root element named in the options.
- Keys that start with “@” become attributes,
"#text"becomes the element’s text. - An array becomes repeated elements with the key’s name. Arrays inside arrays are wrapped, and their items are named after the option “Name for list items”.
nulland""become an empty element, for example<note/>. An empty array produces no element.- Keys that are not valid XML names are adjusted: invalid characters become “_”, and a name that starts with a digit gets a “_” in front.
Questions and answers
Why is my data inside an extra <root> element?
An XML document has exactly one top element. When the JSON has several top-level keys or is an array, the page adds one; you can rename it in the options.
What if a key that starts with “@” holds an object?
An attribute can hold only text, so the object or array is written into it as JSON text, and a note says so.
What happens to arrays, null and empty strings?
An array becomes one element per item, each with the key’s name. Arrays inside arrays are wrapped in an element whose items are called “item” (you can change the name). null and "" become an empty element such as <note/>. An empty array produces no element.
What if a key is not a valid XML name?
Characters that XML names cannot contain are replaced with “_”, and a name that starts with a digit gets a “_” in front: “first name” becomes first_name and “1st” becomes _1st. The notes next to the result list the renamed keys.
Which characters are escaped?
&, < and > in text, and &, <, " as well as tabs and line breaks in attribute values. Control characters that XML 1.0 does not allow, such as U+0001, stop the conversion with the path of the value.