JSON to XML Converter
Convert JSON to well-formed XML (attributes, text nodes, arrays, valid element names) or turn XML back into JSON.
Or drop a .json file here
or click to browse — max 5 MB, read locally
When you need to turn JSON into XML
Most modern APIs speak JSON, but plenty of systems still expect XML: SOAP services, payment and banking gateways, e-invoicing formats, RSS feeds, Android resources and older enterprise integrations. Converting by hand is tedious and easy to get wrong, because the two formats do not map one-to-one. XML needs exactly one root element, element names have strict rules, and there is no native concept of an array or of a number.
This converter applies a predictable set of rules so the output is always well-formed XML. It also works in reverse, turning an XML document into JSON with the same conventions, which is handy when you need to inspect a SOAP response or migrate an XML config to JSON.
How to use it
- Pick the direction with JSON → XML or XML → JSON.
- Paste your data into the input box, drop a .json / .xml file on the drop area, or click Load example.
- Adjust the options (root element name, array handling, attribute prefix, indentation). The output updates as you type.
- Check the notes under the output: renamed keys and removed control characters are listed there.
- Click Copy or Download to save converted.xml or converted.json.
Worked example
This is the built-in example: an order with an attribute, a repeated array and a value with a currency attribute.
{
"order": {
"@id": "A-1001",
"customer": "Ada & Co",
"items": [
{ "sku": "KB-01", "qty": 2 },
{ "sku": "MS-07", "qty": 1 }
],
"price": { "@currency": "EUR", "#text": 49.9 },
"note": null
}
}With Wrap in root element unticked (the JSON has a single top-level key, soorder can be the root) and 2-space indentation, the tool produces:
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1001">
<customer>Ada & Co</customer>
<items>
<sku>KB-01</sku>
<qty>2</qty>
</items>
<items>
<sku>MS-07</sku>
<qty>1</qty>
</items>
<price currency="EUR">49.9</price>
<note/>
</order>Notice that & is escaped, @id became an attribute, the two array entries became two <items> siblings andnull became a self-closing element. With the wrapper ticked (the default) the same content is placed inside <root>.
Options and conversion rules
- Root element name / Wrap in root element — XML allows only one root. When wrapping is on, everything goes inside this element; when it is off, the JSON must be an object with exactly one key, which becomes the root.
- Arrays — "Repeat the key" emits one element per item with the key's name (the usual convention for feeds and SOAP). "Wrap items" keeps a single container element and names each child with the Array item name.
- Attribute prefix — keys starting with it (default @) become attributes. Clear the field to treat every key as an element.
- Text key — the value under #text becomes the element's text, so an element can have attributes and text at the same time.
- Names — characters not allowed in XML names become _, and a _ is prepended when a name starts with a digit, hyphen or dot.
- Escaping — &, < and > are escaped in text; quotes, tabs and line breaks are also escaped inside attribute values. Control characters that XML 1.0 forbids are removed.
- XML → JSON — attributes get the prefix, repeated sibling elements become arrays, mixed text goes into #text, CDATA is read as text and comments are ignored. The root element name is kept as the top-level key.
Limitations
- It does not read or validate against an XSD or DTD, so it cannot know which elements must be attributes or which order a schema requires.
- Namespace prefixes are kept as part of the name but not resolved or checked.
- XML → JSON cannot tell a one-item list from a single value, and mixed content (text between child elements) is merged into one #text string.
- Inputs are limited to 5 MB to keep the page responsive.
Tips
- If the target system expects a specific root (for example <Invoice>), either type it as the root name or make it the only top-level key of your JSON and untick the wrapper.
- Validate or pretty-print the JSON first with the JSON Formatter if the converter reports a syntax error.
- To read or format the generated XML as a tree, open it in the XML Viewer. For YAML instead of XML, use JSON to YAML.
Frequently Asked Questions
How are JSON arrays converted to XML?
By default each array item becomes a sibling element named after the key, so {"tag": ["a", "b"]} becomes <tag>a</tag><tag>b</tag>. Choose "Wrap items" to get <tag><item>a</item><item>b</item></tag> instead; items of a top-level or nested array always use the "Array item name".
How do I create XML attributes from JSON?
Prefix the key with the attribute prefix (default "@"). {"price": {"@currency": "EUR", "#text": 49.9}} becomes <price currency="EUR">49.9</price>. The same prefix and "#text" key are used when converting XML back to JSON.
What happens to keys that are not valid XML element names?
XML names cannot contain spaces or start with a digit, so the converter replaces invalid characters with "_" and adds a leading "_" when needed ("first name" → first_name, "2fa" → _2fa). Every renamed key is listed under the output.
Does it support XML namespaces?
Only as plain names. A key such as "soap:Body" is kept as a prefixed element name and "@xmlns:soap" becomes an attribute, but the tool does not validate that prefixes are declared or resolve namespace URIs.
Is converting JSON to XML and back lossless?
Not always. XML has no data types, so numbers and booleans come back as strings unless you tick "Convert numbers and true/false", an array with one item comes back as a single value, and both null and empty strings become empty elements.
Is my data uploaded anywhere?
No. Conversion runs entirely in your browser with JavaScript and the built-in DOMParser; files you drop are read locally and nothing is sent to a server.
Related tools
- JSON ViewerView, validate and explore JSON with syntax highlighting and interactive tree view
- JSON FormatterFormat and beautify JSON with syntax highlighting and validation
- CSV ↔ JSON ConverterConvert between CSV and JSON formats
- Excel to JSON ConverterConvert Excel, ODS or CSV sheets to JSON — or JSON arrays back to .xlsx. Choose sheet, header row, date and empty-cell handling. 100% client-side.
- JSON to TypeScriptGenerate TypeScript interfaces from JSON objects
- XML ViewerValidate, format, and explore XML documents with an interactive collapsible tree view. Supports .xml, .xsd, .svg, .rss, .plist and any XML-based format. Runs entirely in your browser.
Found a bug or a wrong result? Report it.