How the JSON to XML works
The converter parses your JSON with a strict parser and writes the whole document inside one root element, named
root unless you choose another name. Each object property becomes a child element with the property name,
and strings, numbers and booleans become the element text. Numbers are copied exactly as written.
Arrays inside an object can be written in two ways. Repeat writes one element per item with the
property name, for example <tags>a</tags><tags>b</tags>.
Wrap writes a single <tags> element that contains one child per item, named
item by default. Items of a top-level array and of arrays nested directly in arrays always use the item
element name. null, empty objects and empty arrays become self-closing elements such as <note/>.
Property names that are not valid XML element names are changed: characters that are not allowed become
_, and a name that starts with a digit, -, . or the reserved letters
xml gets a leading _, so first name becomes first_name and
1st becomes _1st. In text, &, < and >
are escaped, carriage returns are written as , and control characters that XML 1.0 cannot
contain are replaced with U+FFFD. The status message tells you when either change was made.
How to use the JSON to XML
- Paste your JSON into the input box, open a .json file, or select Load example.
- Set the root element name, choose how arrays are represented and the array item element name, pick the indentation, and tick or untick Add XML declaration.
- Select Convert to XML, or press Ctrl + Enter (Cmd + Enter on a Mac).
- Copy the XML or download it as an .xml file. The status message tells you if any element names had to be changed.
Example
This input:
{"id": 7, "name": "Tom & Jerry", "tags": ["a", "b"], "address": {"city": "Oslo"}, "note": null}
is converted with the default options to:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<id>7</id>
<name>Tom & Jerry</name>
<tags>a</tags>
<tags>b</tags>
<address>
<city>Oslo</city>
</address>
<note/>
</root>
With Wrap items in child elements, the tags are written as:
<tags>
<item>a</item>
<item>b</item>
</tags>
Common use cases
- Sending data from a JSON API to a SOAP service or another system that only accepts XML.
- Creating XML test data or configuration files from existing JSON samples.
- Feeding JSON data into XSLT transformations or XML-based reporting tools.
- Comparing how the same data looks in JSON and XML when designing an integration.
Frequently asked questions
How are arrays converted?
With Repeat the element for each item, an array property such as "tags": ["a", "b"] becomes <tags>a</tags><tags>b</tags>. With Wrap items in child elements, it becomes a single <tags> element containing <item>a</item><item>b</item>. Items of a top-level array, and arrays nested directly inside arrays, always use the array item element name.
What happens to keys that are not valid XML names?
Characters that are not allowed in an XML element name are replaced with an underscore, and names that start with a digit, a hyphen, a dot or the letters xml get a leading underscore. For example, first name becomes first_name and 1st becomes _1st. Colons are replaced too, so no namespace prefixes are created.
How are special characters escaped?
&, < and > in text are written as &, < and >, and carriage returns as so they survive XML parsing. Control characters that XML 1.0 does not allow at all are replaced with the U+FFFD replacement character, and the status message tells you when that happened.
How are null values and empty objects written?
null, empty objects and empty arrays become self-closing elements such as <note/>. An empty string becomes an element with no content, such as <note></note>.
Is my data uploaded to your server?
No. The conversion runs in your browser, and the JSON you paste or open is not sent to our server.