JSON to XML
Convert JSON to XML format
About JSON to XML
JSON to XML writes pasted JSON as an indented XML document that starts with an XML declaration and wraps everything in a root element. Each key becomes a tag; an array becomes the same tag repeated, and a top-level array becomes item elements. Keys that start with @_ become attributes and a #text key becomes the text of its element, following the fast-xml-parser conventions. Text is escaped, numbers are kept as written, and a key that cannot be an XML name is reported instead of producing broken XML.
Example
A book object with an @_id key, an array, and an ampersand, and the XML the tool returns:
JSON
{
"book": {
"@_id": "7",
"title": "Tom & Jerry",
"tags": ["kids", "cartoon"],
"price": 12.50
}
}XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<book id="7">
<title>Tom & Jerry</title>
<tags>kids</tags>
<tags>cartoon</tags>
<price>12.50</price>
</book>
</root>
How to convert JSON to XML
- 1Paste JSON into "JSON input"; put @_ before any key you want as an attribute.
- 2Click "Convert".
- 3Read the XML in "XML output", or the message naming a key that is not a valid XML name.
- 4Use "Copy", or "Download" for a data.xml file.
Formats and limits
- Input
- JSON text
- Output
- XML with a declaration, a root element, and two-space indentation; file data.xml
- Element names
- a letter or _ first, then letters, digits, _ . - or :
Where your file is processed
The XML is built in your browser by the fast-xml-parser library, loaded when you first click "Convert"; your JSON is not uploaded. When a conversion fails, a report reaches us with the error text, quoted parts masked, the tool name, and your browser name and version.
Frequently asked questions
Can I create XML attributes?
Yes. Prefix the key with @_: a book object holding @_id with the value 7 gives <book id="7">. A #text key next to it becomes the element's text, so one element can carry both attributes and content.
Does the output have a single root element?
Yes. An XML document needs exactly one, so the result is always wrapped in <root>; a JSON array at the top level gives one <item> per entry inside it. Rename root afterward if your system expects another name.
Are special characters escaped?
Yes. & becomes & and < becomes < in text, as the example shows, so the document stays well-formed. A key with a space, or one that starts with a digit, is refused with a message, because no escaping can turn it into a valid tag name.
Are numbers written exactly as in the JSON?
Yes. The JSON is read without turning numbers into floating point, so a price of 12.50 gives <price>12.50</price> and a 20-digit ID keeps every digit in its element. A null value becomes an empty element.
Tips and tricks
- ✓To read XML back into JSON, with attributes as @_ keys, use XML to JSON.