How to use the JSON to XML
- Paste the JSON. A single top-level key becomes the root element; otherwise a wrapper root is added.
- Review element names: keys that are not valid XML names are adjusted.
- Check how arrays came out – each item repeats the parent key's element.
- Copy or download the .xml file.
Worked example
A book with two tags
Input
{"book":{"id":"b1","title":"Dune & Sons","tags":["sci-fi","classic"],"price":9.99}}XML
<?xml version="1.0" encoding="UTF-8"?> <book> <id>b1</id> <title>Dune & Sons</title> <tags>sci-fi</tags> <tags>classic</tags> <price>9.99</price> </book>
The & is escaped as &. The two-item array produces two <tags> elements; a one-item array produces one, which is indistinguishable from a plain value once in XML.
What does not map one-to-one
| JSON feature | XML outcome |
|---|---|
| Several top-level keys | Wrapped in a single root element (XML allows only one) |
| Key like "2fa" or "first name" | Not a valid element name; adjusted, e.g. prefixed or with _ |
| Arrays | Repeated sibling elements |
| null | Empty element such as <x/> |
| Numbers and booleans | Text; XML has no types without a schema |
| Nested arrays [[1,2]] | Need a wrapper element per inner array |
Attributes
JSON has no concept of attributes, so by default everything becomes child elements. Many converters adopt a convention where a key prefixed with @ (for example "@id") is written as an attribute and "#text" as element text. If the target system needs attributes, check the converter options for such a prefix and rename the keys before converting.
Escaping and encoding
Inside element text, < and & must be escaped as < and &; the converter does this for you. Control characters below U+0020 other than tab, newline and carriage return are not allowed in XML 1.0 at all, even escaped, so strip them from strings before converting.
JSON to XML FAQ
How are JSON arrays represented in XML?
As repeated elements with the same name: "tags":["a","b"] becomes <tags>a</tags><tags>b</tags>. Some systems expect a wrapper like <tags><tag>a</tag></tags>; restructure the JSON first if so.
Why does my XML need a single root element?
The XML specification allows exactly one top-level element per document. When the JSON object has several keys, they are placed inside a wrapper root.
Can JSON keys contain characters that XML names cannot?
Yes. XML names cannot start with a digit or contain spaces, while JSON keys can be any string. Such keys are renamed in the output so the XML stays well-formed.
Does the XML output include a schema or types?
No. The values are plain text. If the receiver validates against an XSD, compare the generated element names and order with the schema.
Is the conversion reversible?
Not exactly. A one-item array and a single value look the same in XML, and numbers come back as text unless the reverse converter guesses types.

