JSON to XML Converter with Attributes and Array Items
Convert JSON to well-formed XML with @attribute keys, repeated array elements and name sanitizing
How JSON is mapped to XML
This JSON to XML converter follows the same conventions as the XML to JSON tool on this site, so the two work as a pair. Each object key becomes a child element and each primitive value becomes that element's text: {"title": "Dune"} turns into <title>Dune</title>. Keys starting with the attribute prefix ("@" by default) become attributes on the parent element instead, so {"book": {"@id": "7", "title": "Dune"}} produces <book id="7"><title>Dune</title></book>. A key equal to the text key ("#text" by default) becomes the element's own text alongside its attributes or children, which is how you write <price currency="USD">9.99</price>.
Arrays are the part where JSON to XML converters differ most. Here an array under a key repeats that element once per item — {"tag": ["a", "b"]} becomes <tag>a</tag><tag>b</tag> — which is the natural XML shape and what most XML consumers expect. A bare array with no key of its own (a top-level array, or an array inside an array) is wrapped, and each item becomes an <item> element; you can rename that item element. null and empty strings become self-closing elements such as <middleName/>, and an empty array produces no elements at all. Numbers and booleans are written as text. A typical API response such as {"users": [{"id": 1}, {"id": 2}]} therefore becomes a <root> element containing two <users> elements, each with an <id> child; if you want a wrapping <users> element with <user> children instead, shape the JSON that way first, for example {"users": {"user": [...]}}.
Root element, names and escaping
XML needs exactly one root element. If your JSON is an object with a single key whose value is not an array, that key is used as the root. Otherwise — several top-level keys, a top-level array or a plain value — the output is wrapped in the root element name you set, "root" by default.
JSON keys can contain anything, but XML element names cannot start with a digit or contain spaces and most punctuation. Instead of producing broken XML, invalid characters are replaced with underscores and a leading underscore is added where needed, so "1st place" becomes <_1st_place>. Every renamed key is listed under the output so you know exactly what changed. Namespace-style names such as soap:Body are kept as they are.
Text and attribute values are escaped: & becomes &, < becomes <, > becomes > and, inside attributes, double quotes become ". Control characters that XML 1.0 forbids entirely are removed rather than escaped, because no escape makes them legal.
Formatting options and privacy
Choose two-space, four-space or no indentation; with no indentation the whole document is written on one line, which is handy for embedding in a request body. The XML declaration (<?xml version="1.0" encoding="UTF-8"?>) is included by default and can be switched off when you are producing a fragment to paste inside another document.
The JSON is parsed with JSON.parse and converted in your browser, so nothing is uploaded. Invalid JSON shows the parser's error message instead of partial output. To check the result, paste it into the XML to JSON converter — with matching prefix and text key settings you get back the structure you started from.
How to use the JSON to XML Converter with Attributes and Array Items tool
- 1
Paste your JSON
Any valid JSON: an object, an array or a single value.
- 2
Set root and item names
Used when the JSON has no single top-level key or contains bare arrays.
- 3
Choose prefix, indent and declaration
Match the attribute prefix and text key to your data, pick an indent and toggle the XML declaration.
- 4
Copy or download the XML
Renamed keys are listed under the output so nothing changes silently.
Frequently asked questions
How do I make a JSON key an XML attribute?
Prefix it with @ (or your chosen prefix): {"user": {"@id": "5", "name": "Ann"}} becomes <user id="5"><name>Ann</name></user>.
How are JSON arrays converted to XML?
An array under a key repeats that element for each item, so "tag": ["a","b"] becomes two <tag> elements. Arrays without a key are wrapped and their items become <item> elements.
What happens to keys that are not valid XML names?
Invalid characters become underscores and names starting with a digit get a leading underscore, for example "2fa code" becomes <_2fa_code>. Every change is listed under the output.
Why was my JSON wrapped in <root>?
XML allows only one root element. When the JSON is not an object with a single key, the converter wraps it in the root name you set.
Is the conversion done on a server?
No. Parsing and conversion run entirely in your browser, so your JSON never leaves your device.
Related on TechLogHub
Related Converter Tools
Unix Timestamp Converter with Milliseconds
Convert Unix timestamps to human-readable dates and vice versa
Cron Expression Generator with Next Run Times
Build, explain and test cron expressions, with the next run times in UTC and your timezone
ENV to JSON
Convert .env files to JSON format
ENV to Docker Compose
Convert .env files to docker-compose environment snippet
Query String to JSON
Parse URL query strings into JSON objects
JSON to Query String
Convert JSON objects to URL query strings
Get the next tool before you need it
One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.

