How to convert JSON to XML, free and without uploading
To convert JSON to XML, paste your JSON into the JSON Input box, click Open JSON File, or click Load Sample to try it. The XML Output box appears about 0.25 seconds after you stop typing, with a note that the XML is well-formed. Keys become elements, keys that start with @ become attributes, #text sets an element's text, and a single top-level key whose value is an object becomes the root element. Click Copy, or Download XML to save converted.xml. The built-in sample, 798 characters of JSON, becomes 604 bytes of indented XML with 16 elements and 9 attributes when Array Style is set to Unwrapped (repeated).
It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). Files chosen with Open JSON File are read on your device. There is no account and nothing to install.
JSON has objects, arrays and values, while XML has elements, attributes and text, and no official rule maps one to the other. This converter uses the common convention: @name and _attributes make attributes, and #text makes text. Every XML document needs a single root, so the converter either promotes a single top-level key that holds an object or wraps the data in the Root Element name.
To go the other way, use the XML to JSON converter. Check the input with the JSON validator or the JSON formatter, and re-indent or inspect the result with the XML formatter and the XML validator.
Table of Use: how JSON becomes XML
| In your JSON | XML output | Note |
|---|---|---|
{"a":{"b":1}} | <a>
<b>1</b>
</a> | A single top-level key whose value is an object becomes the root element when the checkbox under Root Element is ticked |
{"a":1,"b":2} | <root>
<a>1</a>
<b>2</b>
</root> | With several top-level keys, everything goes inside the name typed in Root Element |
{"price":{"@currency":"USD","#text":"10.99"}} | <price currency="USD">10.99</price> | @ keys become attributes and #text becomes the element text |
{"p":{"_attributes":{"id":"7","lang":"en"},"#text":"hi"}} | <p id="7" lang="en">hi</p> | An _attributes object holds several attributes at once |
"b": [1, 2] with Wrapped (item elements) | <b>
<item>1</item>
<item>2</item>
</b> | The default; Array item element name changes item |
"b": [1, 2] with Unwrapped (repeated) | <b>1</b>
<b>2</b> | The key is repeated once for each array entry |
{"a":null,"b":[],"c":"","d":true} | <a/>
<b/>
<c></c>
<d>true</d> | null and empty objects give an empty element, and so do empty arrays in the default Wrapped style (Unwrapped writes nothing for an empty array); an empty string gives an empty pair of tags |
"my key", "1st" | <my_key>, <_1st> | Invalid names are repaired and listed in a note under the output |
{"t":"a < b & c"} | <t>a < b & c</t> | Text and attribute values are escaped |
"@xmlns:h": "http://www.w3.org/TR/html4/", "h:table": {...} | <h:table> | A prefix declared with @xmlns:prefix is kept; an undeclared one becomes h_table |
The default Array Style is Wrapped (item elements), so the built-in sample produces <book><item id="1">. Set Array Style to Unwrapped (repeated) to get one <book> element per entry instead. The rows leave out the XML declaration line, which the tool adds by default.
Features
- Root Element control. Type any name, or tick the checkbox to use a single top-level key with an object value as the root. A scalar or a top-level array is wrapped in the root name.
- Attributes, text and namespaces.
@keyor an_attributesobject makes attributes,#textsets text, and@xmlns:prefixdeclares a namespace. With #text and child elements, the text comes first. - Two array styles. Wrapped (item elements) or Unwrapped (repeated), with an Array item element name. Nested arrays keep a wrapper, so no level of the data is lost.
- Indentation and declaration. 2 Spaces, 4 Spaces, Tab or None (single line), plus an XML declaration checkbox that adds
<?xml version="1.0" encoding="UTF-8"?>. Compare two settings in the text diff tool. - Names and characters repaired. Keys that are not valid XML names are renamed, and control characters XML 1.0 forbids are replaced with ๏ฟฝ. Both are reported in an amber note under the output.
- Checked by your browser. The output is parsed with the browser's XML parser, and a green or red line says whether it is well-formed.
- Exact values and counts. Numbers and key order are kept as written, and the Elements, Attributes and Output Size boxes give the totals.
How to use the JSON to XML converter
- Paste your JSON into the JSON Input box, click Open JSON File, or click Load Sample. Click Clear All to start again.
- Under Root Element, type a name, or leave the checkbox ticked to use a single top-level key with an object value as the root.
- Pick an Indentation, then choose Array Style and, if you like, an Array item element name.
- Tick or untick XML declaration.
- Check the XML Output, the well-formed line and the Elements and Attributes counts. Read the amber note if keys were renamed.
- Click Copy, or Download XML to save the file. It is named
converted.xml, or after the opened file with a.xmlextension.
Who can use it
- Developers who must send data to a system that only accepts XML. Site owners who just need an XML sitemap can skip JSON and use the sitemap generator.
- Analysts who want the same data as a table, using the JSON to CSV converter.
- Configuration writers moving data between formats, including the JSON to YAML converter.
- Testers building XML fixtures from JSON samples, with exact numbers and a predictable element order.
- Students learning how the two formats differ, by comparing the input with the XML Output.
FAQs
How do I convert JSON to XML?
Paste your JSON into the JSON Input box, click Open JSON File, or click Load Sample to try it. The XML Output box appears about 0.25 seconds after you stop typing, with a note that the XML is well-formed. Change the Root Element, Indentation or Array Style if you need to, then click Copy, or Download XML to save converted.xml.
How do I create XML attributes and text content?
JSON has no attributes, so the converter follows a common convention. A key that starts with @ becomes an attribute, so "@id": "1" gives id="1", and an _attributes object does the same for several at once. A #text key sets the element's text, which is how an element can hold both an attribute and a value, as in <price currency="USD">10.99</price>.
Why do my arrays come out wrapped in item elements?
Array Style defaults to Wrapped (item elements), which writes the array as one element holding an item element for each entry. Switch it to Unwrapped (repeated) to repeat the key instead, so "book": [...] becomes several book elements. Array item element name changes item to another name. A top-level array is always placed inside the root element.
How is the root element chosen?
XML needs exactly one root. If your JSON has a single top-level key whose value is an object, that key becomes the root, as long as the checkbox under Root Element is ticked. Otherwise the converter wraps everything in the name you type in Root Element, which starts as root. A top-level array or plain value is wrapped the same way.
What happens to keys that are not valid XML names?
The converter repairs them so the XML stays well-formed. A space or slash becomes an underscore, and a name that starts with a digit or hyphen gets an underscore in front, so "my key" becomes my_key and "1st" becomes _1st. A note under the output lists the renamed keys. Letters from other alphabets, such as รฉ, are allowed in names.
Are numbers and special characters preserved?
Numbers are copied exactly as written, so 12345678901234567890 and 1.50 are not rounded or trimmed. The characters <, > and & are escaped in text, and quotes are escaped in attribute values. Control characters that XML 1.0 forbids are replaced with the character ๏ฟฝ and counted in a warning. null becomes an empty element such as <a/>.
Does it support namespaces, CDATA or comments?
Namespaces, yes: add a key such as "@xmlns:h" with the namespace URL, and keys written like h:table keep their prefix. A prefix that is not declared is turned into an underscore. The converter does not write CDATA sections, comments, processing instructions or a DTD, and it does not validate against a schema. It only makes elements, attributes and text.
Is my JSON uploaded to a server?
It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). The JSON is parsed and converted by a script that ships with the page, and the result is checked with your browser's own XML parser. Files chosen with Open JSON File are read on your device. Nothing is sent to ZipConvert or anyone else.