How to use it
- Paste the JSON into JSON. Its one top-level member becomes the root element.
- Use the @ prefix for attributes, such as @id, and #text for the text of an element.
- Choose an Indentation, or No line breaks (minified) for the shortest XML.
- Copy the XML, or download it as converted.xml.
The mapping, rule by rule
XML has elements and attributes; JSON has objects, arrays and values. The mapping joins them in one direction. The top level is an object with one member: its name is the root element. An object becomes an element. A member whose name starts with @ becomes an attribute, and a member named #text becomes the text of the element. Any other member becomes a child element with that name.
An array gives one child element per item, all with the name of the array, so a list of books is written as repeated book elements. A string, a number or true or false becomes text. null, and an empty object, become an empty element. An empty array has no XML form and is left out.
- A name must be an XML name: a key such as first name, with a space, cannot be written as an element name.
- An array inside an array is refused, because there is no element name to give its items.
- The text of a number is written as JavaScript writes it, so a number with more than 15 or 16 significant digits may lose digits, as JSON reading does.
What the mapping cannot keep
XML has no types, so the difference between the number 12 and the text "12" is lost on the way back; the XML to JSON converter reads text that looks like a number as a number unless its typing is turned off. An empty object and null look the same in XML, and an array with one item comes back as that item. These are the limits of the mapping, not errors of the tool.
Comments and processing instructions are not written, because JSON has nowhere to keep them. A text inside an element is escaped, so &, < and > stay as text in the XML.
Worked example: the default catalog
The default JSON has one member, catalog. Its @version becomes the version attribute of the catalog element, and its book array becomes two book elements. Each book takes its @id as the id attribute, and its title, price and inStock keys become child elements. The price null of the second book becomes the empty element price.
With two spaces and the declaration, the output has eight elements: the catalog, two books, and three children of the first book and two of the second. The count shows 8.
Frequently asked questions
How do I write an attribute in JSON?
Give the key an @ prefix. The member "@id": "1" becomes id="1" on the element that holds it. Attribute values must be text, numbers or true or false, not objects or arrays.
Why does my array become several elements with the same name?
XML has no array. Each item of the array becomes one element with the array's name, in the same order, which is the usual way XML lists repeated things such as books or items.
Why do I get an error about the top level?
The XML needs exactly one root element. The JSON must be one object with one member, such as {"catalog": {...}}; a list or several members at the top level cannot be one document.
Why is a key with a space refused?
Element names in XML cannot contain spaces. Rename the key, for example to first-name or firstName, before converting it.
Is my JSON sent to a server?
No. The conversion runs in your browser. Nothing you paste is sent to our server or stored there.
Sources
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
- W3C: Extensible Markup Language (XML) 1.0, Fifth Edition
Figures and text last checked on Tuesday, November 10, 2026.