JSON to XML Converter
Convert JSON to XML online with a root element, attributes through a prefix, repeated elements for arrays and proper escaping. Invalid tag names are fixed for you.
How to use JSON to XML
- 1Paste JSON into the input box, or open a .json file.
- 2Set the root element name, the attribute prefix, the indent and whether to add the XML declaration.
- 3Copy the XML or download it as a .xml file. The Mode switch above the options also formats, minifies, validates or browses XML.
What makes it better
- Mode switch for Format, Minify, Validate, XML to JSON and a Tree view
- Root element name you choose, or use the single top-level key
- Attribute convention: keys with the prefix (default @_) become attributes
- Escapes & < > and quotes, and removes characters XML forbids
- A validity line under the options checks your input in every mode
About JSON to XML
JSON to XML writes your JSON as well-formed XML. Keys starting with @_ become attributes, arrays become repeated elements, and characters such as & and < are escaped. Keys that are not valid XML names are repaired and the page tells you exactly what changed, and JSON that would need more than one root element is refused unless you wrap it. Switch to Format, Minify, Validate, the other conversion direction or a Tree view without leaving the page: your text stays in the box.
Common uses
- Build an XML request body for a SOAP or legacy service from JSON you already have.
- Convert JSON configuration into the XML a Java or .NET application expects.
- Produce a sitemap-like or feed-like XML skeleton from sample JSON data.
- Check how a JSON structure maps to elements and attributes before writing a mapping by hand.
Example
Input
{
"order": {
"@_id": "1001",
"customer": "Ada & Co",
"items": ["pen", "ink"],
"note": null
}
}Result
<?xml version="1.0" encoding="UTF-8"?>
<root>
<order id="1001">
<customer>Ada & Co</customer>
<items>pen</items>
<items>ink</items>
<note/>
</order>
</root>Good to know
- XML has no types: numbers, booleans and strings all become text, and null becomes an empty self-closing element. Reading it back as JSON returns text values.
- Element order follows the key order in the JSON. Attributes are written on their element's opening tag, whatever their position among the keys.
- Names that start with a digit or contain spaces cannot be XML names. They are changed (for example 1st becomes _1st) and listed under the result. Empty arrays produce no elements at all.
JSON to XML FAQ
How do I convert JSON to XML?
Paste the JSON, choose a root element name and read the XML that appears. Each object key becomes an element, each array item a repeated element, and keys beginning with the attribute prefix become attributes of their element.
Why does the XML need a root element?
An XML document must have exactly one top-level element, while JSON can hold many keys or an array at the top. The root name you enter wraps everything. If you clear it, the JSON must have a single top-level key, which then becomes the root.
How do I write XML attributes in JSON?
Start the key with the attribute prefix, which is @_ by default, for example "@_id": "7" produces id="7" on the element. Text placed next to attributes goes in a "#text" key. You can change the prefix in the options.
What happens to keys that are not valid XML names?
Spaces and symbols are replaced with underscores and a name that starts with a digit gets an underscore in front. If two keys end up identical, the second gets a number. Every change is listed so you can fix the JSON instead.
How are arrays and null written?
An array under a key becomes that element repeated once per item. An array directly inside another array uses <item> elements. null becomes a self-closing tag such as <note/>, and an empty string becomes an open and close pair with nothing between.