Output appears here.
JSON to XML converts a JSON object or array into well-formed, indented XML, with a configurable root element and support for attributes. Use it when a SOAP service, a legacy integration or an XML-only import expects data you have as JSON. Special characters are escaped for you. Conversion runs in your browser; nothing is uploaded.
How to convert JSON to XML
- Paste JSON, drop a
.jsonfile, or press ⌘/Ctrl O. - Choose a Root element. Pick None (single key) when your JSON already has one top-level key that should become the root, and decide whether to include the XML declaration.
- Copy the XML with ⌥/Alt C or download it with ⌘/Ctrl S. Next actions open it in the XML Formatter or convert it back to JSON.
Examples
Order with an attribute, no extra root
The JSON has a single top-level key, order, so Root element is set to None (single key). Keys prefixed with @_ become attributes, and the item array becomes repeated <item> elements.
{"order":{"@_id":"A-1","customer":"Acme","items":{"item":[{"sku":"K-1","qty":2},{"sku":"M-3","qty":1}]}}}Result:
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1">
<customer>Acme</customer>
<items>
<item>
<sku>K-1</sku>
<qty>2</qty>
</item>
<item>
<sku>M-3</sku>
<qty>1</qty>
</item>
</items>
</order>Top-level array
A JSON array has no names for its elements, so each record becomes an <item> inside the root. Here the root is <data> and the declaration is off.
[{"id":1,"customer":"Acme Ltd","paid":true},{"id":2,"customer":"Globex","paid":false}]Result:
<data>
<item>
<id>1</id>
<customer>Acme Ltd</customer>
<paid>true</paid>
</item>
<item>
<id>2</id>
<customer>Globex</customer>
<paid>false</paid>
</item>
</data>Escaping, empty values and text with attributes
Default <root>, 4-space indent. & and < are escaped, empty strings and nulls become empty elements, and #text next to an @_ key produces an element with both an attribute and text.
{"note":"Tom & Jerry <3","empty":"","nil":null,"tags":["a","b"],"n":{"#text":"5","@_unit":"kg"}}Result:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<note>Tom & Jerry <3</note>
<empty/>
<nil/>
<tags>a</tags>
<tags>b</tags>
<n unit="kg">5</n>
</root>Options explained
- Indent — the whitespace used for each nesting level in the XML: 2 spaces, 4 spaces or a tab.
- Root element — wraps the output in
<root>or<data>; None (single key) uses your JSON's only top-level key as the root and falls back to<root>when there is more than one key or the input is an array. - XML declaration — adds
<?xml version="1.0" encoding="UTF-8"?>as the first line; turn it off when the XML will be embedded in a larger document or a SOAP body.
Common JSON to XML errors
"Keys "2fa", "first name" cannot be used as XML element names."
XML element names cannot start with a digit, contain spaces or use most punctuation, while JSON keys can be anything. The message lists every key that cannot become an element, by its name in your JSON. Rename those keys before converting.
Two root elements, or an extra <root>
XML needs exactly one root. None (single key) only works when the JSON has one top-level key; otherwise the output is wrapped in <root> so it stays well-formed. Choose <data> or add a single top-level key to control the name.
Arrays appear as repeated elements
An array under a key such as tags becomes one <tags> element per value, since XML has no list type. For a wrapper element with children, nest the array: {"tags": {"tag": ["a", "b"]}} produces <tags><tag>a</tag><tag>b</tag></tags>.
Null and empty string look the same
Both become an empty element such as <nil/>. If the receiving system must tell them apart, send a marker value or an attribute in the JSON before converting.
Invalid JSON input
Errors show the line, column and likely cause, as in the JSON Validator. Comments and trailing commas are tolerated and removed, and a notice such as "Removed 1 trailing comma." says what was dropped, so JSONC files convert without changes.
FAQ
Is it safe to convert JSON with customer data?
Yes. The conversion runs in your browser inside an isolated frame that blocks network requests, so the JSON and the generated XML never leave your device, and nothing is stored on a server. Your settings are remembered locally; the input itself is only kept if you turn on "Remember my last input".
How do I create XML attributes from JSON?
Prefix the key with @_. {"price": {"@_currency": "USD", "#text": "44.95"}} becomes <price currency="USD">44.95</price>. Use #text for the element's text when it also has attributes. This is the same convention XML to JSON produces by default, so the two convert cleanly in both directions.
Are data types kept?
XML text has no types, so numbers and booleans are written as text: 2 becomes <qty>2</qty> and true becomes <paid>true</paid>. The receiving system decides how to interpret them, usually through an XSD. When converting back, Convert numbers & booleans in XML to JSON restores the types.
Can I build a SOAP request with this?
Yes, for the body. Build the payload as JSON with the element names the service expects, convert it with the declaration off, and paste the result into the soap:Body of your envelope. Namespace prefixes can be written directly into keys, such as "m:GetPrice", and @_xmlns:m adds the namespace declaration.
What happens to special characters?
&, < and > in values are escaped as &, < and >, so the output is always well-formed. Non-ASCII characters such as é or ₹ are written as they are, which is correct for the UTF-8 encoding named in the declaration.
Related tools
Check the input first with the JSON Formatter, and tidy or minify the output with the XML Formatter. For configuration formats rather than XML, see JSON to YAML.