Quick answer
To convert JSON to XML, paste your JSON into the JSON box. Set the root element name, the array items element name, the indent (2 spaces, 4 spaces, tab or minified) and whether to add the <?xml version="1.0"?> declaration. Keys starting with @ become XML attributes and #text becomes element text. The XML appears instantly — copy it or download it. Invalid JSON is reported clearly.
- Input:
- Any valid JSON object or array
- Root element:
- Custom name
- Arrays:
- Repeated elements with a custom item name
- Attributes:
- Keys starting with @ become attributes
- Text:
- #text key becomes element content
- Formatting:
- 2 spaces, 4 spaces, tab or minified
- Declaration:
- Optional XML declaration
- Upload needed:
- No – runs in your browser
JSON and XML are the two most common formats for exchanging structured data. Modern web APIs mostly speak JSON, but many established systems still require XML: payment gateways and banks, government and tax portals, ERP and accounting software, product feeds for marketplaces and shopping engines, RSS feeds, SOAP web services, office document formats and countless enterprise integrations. Moving data between these worlds means converting JSON to XML — and doing it by hand is slow and error-prone.
Our JSON to XML converter does it instantly. Objects become nested elements, arrays become repeated elements, and strings, numbers and booleans become element text with special characters safely escaped. Because XML needs a single root element and names for array items, you can set both. Keys that are not valid XML names — for example containing spaces or starting with a number — are adjusted automatically so the output is always well-formed.
For more control over the structure, use the common conventions: a key starting with @ becomes an attribute and a #text key becomes the element's text content. Choose readable indentation or a minified single line, and add the XML declaration when the receiving system requires it.
Conversion happens entirely in your browser, so your data — which may include customer records or orders — stays private.
How to convert JSON to XML – step by step
- 1 Paste your JSONPaste an object or array into the JSON box. Errors are shown if the JSON is invalid.
- 2 Name the rootSet the root element name the target system expects, such as root, data, orders or catalog.
- 3 Name array itemsSet the element name used for items of top-level arrays, such as item or product.
- 4 Choose formattingPick 2 spaces, 4 spaces, tab or minified, and whether to include the XML declaration.
- 5 Copy or downloadCopy the XML or download it as a file and import it into your target system.
Why use this JSON to XML converter?
Well-formed output
Valid element names and escaped special characters.
Custom root and item names
Match the structure the target system expects.
Attributes and text
@key and #text conventions for full control.
Formatting options
Pretty-printed or minified.
XML declaration
Add it when required.
Private and free
Runs in your browser, no sign-up.
How JSON maps to XML
| JSON | XML result |
|---|---|
| {"name": "Rafi"} | <name>Rafi</name> |
| {"user": {"id": 7}} | <user><id>7</id></user> |
| {"tag": ["a", "b"]} | <tag>a</tag><tag>b</tag> |
| {"price": {"@currency": "USD", "#text": 9}} | <price currency="USD">9</price> |
| {"note": null} | <note/> |
| {"first name": "A"} | <first_name>A</first_name> |
JSON vs. XML: key differences
JSON is lighter and maps directly to objects and arrays in JavaScript, Python, PHP and most languages, which is why web APIs prefer it. XML is more verbose but has features JSON lacks: attributes, mixed content (text with embedded tags), namespaces, comments, schemas (XSD) for strict validation and powerful query and transformation languages (XPath, XSLT). Because of these differences, there is no single "correct" conversion — different systems expect different structures. The root and item settings and the @/#text conventions let you shape the output to what the receiving system needs.
Element naming rules
XML element names must start with a letter or underscore and may contain letters, digits, hyphens, underscores and periods — no spaces or most symbols. JSON keys can be anything, so the converter replaces invalid characters with underscores and adds a leading underscore to names starting with a digit. For example, "2024 sales" becomes _2024_sales. If the target system expects specific names, rename the keys in your JSON before converting.
Common uses
- Product feeds — convert product data from a JSON API into the XML format a marketplace or comparison site requires.
- Legacy integrations — send data from a modern app to an older system that only accepts XML.
- SOAP services — prepare XML request bodies from JSON data.
- Configuration — generate XML config files from JSON settings.
- Testing — quickly create XML samples for developing parsers and imports.
- Sitemaps and feeds — draft XML structures (for real sitemaps, use our Sitemap Generator).
Validating your JSON first
The converter needs valid JSON. Common problems are trailing commas, single quotes instead of double quotes, unquoted keys and comments, which are allowed in JavaScript but not in JSON. If you get an error, format and validate the input with our JSON Formatter, which shows exactly where the problem is.
Converting back
To go the other way — XML into JSON — use our XML to JSON converter, which uses the same @attribute and #text conventions, so data can round-trip between the formats.
A worked example: an order export
Imagine an online shop exports orders as JSON: an array of objects, each with an order number, a customer object, an array of line items and a total with a currency. An accounting system needs them as XML. Paste the array, set the root element to orders and the item name to order. Each order becomes an <order> element; the customer object becomes a nested <customer> element; the line items array becomes repeated <items> elements. If the accounting system wants the currency as an attribute — <total currency="BDT">1250</total> — change the total in your JSON to an object with "@currency" and "#text" before converting. A few minutes of reshaping the JSON usually produces exactly the structure the target system documents, without writing any code.
Special characters and encoding
Characters with special meaning in XML — &, <, > and quotes — are escaped automatically, so text like "Tom & Jerry" or "a < b" stays valid. Unicode text, including Bengali, Arabic, Chinese and emoji, is kept as-is; the output is UTF-8, which is the XML default. If a target system needs another encoding, convert the downloaded file with your editor.
XML features JSON cannot express
Some XML features have no direct JSON equivalent, so plan for them when the target system relies on them. Namespaces, such as the xmlns declarations used in SOAP, RSS extensions and Office files, can be added as @xmlns attributes on the root or relevant elements. Element order matters in many XML schemas but JSON objects are conceptually unordered — the converter keeps the order of keys as they appear (except purely numeric keys, which JavaScript always lists first), so arrange your JSON keys in the order the schema demands. Comments and processing instructions are not produced. Mixed content, where text and child elements alternate, is best avoided in data exchange anyway.
Large files
The converter runs in your browser, so it can handle fairly large JSON documents, limited by your device's memory. For files of many megabytes or automated conversions, use a script in your preferred language — for example Python's xml.etree or a library like xmltodict, or PHP's SimpleXML — and use this tool to design and test the structure.
Troubleshooting
- "Unexpected token" error. The JSON is invalid; check for trailing commas, single quotes or comments.
- Element names changed. Keys with spaces or leading digits were made XML-safe.
- Array items have the wrong name. Top-level arrays use the item name; nested arrays repeat their key name.
- The target system rejects the XML. Check its schema: it may need specific element order, namespaces or attributes.
Frequently asked questions
How do I convert JSON to XML?
Paste the JSON, set the root and item names and formatting, then copy or download the XML.
How are JSON arrays converted?
Each array item becomes a repeated element with the same name.
How do I create XML attributes?
Use keys starting with @, for example "@id": 5 becomes id="5".
What does #text do?
It sets the text content of an element that also has attributes.
What happens to invalid element names?
Invalid characters become underscores, and names starting with a digit get a leading underscore.
Can I minify the XML?
Yes. Choose Minified indentation.
Does it add an XML declaration?
Yes, if you enable the option.
Is my data uploaded?
No. Conversion runs in your browser.
Can I convert XML back to JSON?
Yes. Use our XML to JSON converter.
Does it support Unicode?
Yes. Output is UTF-8 and keeps all characters.
Is the converter free?
Yes. No sign-up required.
Does the converter keep the order of my keys?
Yes, in the order they appear in the JSON, except purely numeric keys, which come first.
Last updated November 22, 2026 · Written and tested by the SmallEasyTools team.