How JSON maps onto XML
JSON and XML do not line up exactly, so every converter has to choose conventions. JSON has arrays; XML only has elements that may repeat. XML has attributes and a single root element; JSON has neither. The conventions used here are the common ones, and they are reversible: the XML to JSON converter on this site reads the result back into the same structure.
Objects become elements
Each key is an element name and its value the content. Names that are not valid in XML — with spaces, or starting with a digit — are adjusted with underscores.
Arrays become repeated elements
"items": [a, b] turns into two <items> elements side by side, the way XML usually expresses a list.
@key becomes an attribute
"@id": "A-1042" is written as id="A-1042" on the parent element. "#text" is the element's own text. The prefix can be changed.
One root element
If the JSON is an object with a single key, that key is the root. Otherwise the content is wrapped in the root name you choose.
Escaping and empty values
The characters &, < and > in text are written as entities, and quotes inside attribute values as ", so the result is always well-formed. null and empty strings become self-closing elements such as <note/>. Numbers and booleans are written as text — XML has no types of its own; a schema (XSD) is what gives them one.
Use it when a modern service has to talk to an older one: a SOAP endpoint, an RSS or sitemap feed, a partner integration specified in XML, or a legacy import that only understands one format.
Frequently asked questions
How are JSON arrays represented in XML?
As repeated elements with the same name. An array under the key "item" becomes several item elements in a row. A top-level array is wrapped in the root element, with one element per entry.
Can I produce XML attributes from JSON?
Yes. Prefix the key with @ — for example "@id" — and it is written as an attribute of the parent element instead of a child element.
What happens to keys that are not valid XML names?
Characters that XML does not allow in a name are replaced with underscores, and a name that starts with a digit gets a leading underscore.
Is the output valid XML?
It is well-formed: one root, matched tags, escaped characters and an XML declaration. Whether it is valid for a particular schema depends on that schema.