# JSON to XML

Convert JSON to indented XML, with attributes, arrays and illegal key names handled. Free, no signup, and nothing you paste is uploaded.

Canonical page: https://filetity.com/json-to-xml

## Capabilities

- Free: Yes, with no watermark and no page limit.
- Account required: No. There is no account system.
- Processed on device: Yes. The file is read by your browser and never uploaded. There is no server to send it to.
- Formats: JSON in, as an object, an array or a primitive. Indented XML out, with a declaration and a root element you can name.
- Limits: No size limit beyond what your browser will hold. A key that is not a legal XML element name is rewritten, and that is the one step in this direction that loses information.
- Mobile: Yes, on any modern mobile browser. Large files are limited by the memory the phone gives the browser.
- Offline: Yes, once the page has loaded. The tool keeps working with no network connection.

## Questions

### What happens to a key that is not a valid XML name?

It is rewritten rather than refused. XML element names cannot contain spaces and cannot begin with a digit, so "first name" becomes first_name and "1st" becomes _1st. This is the only lossy step in this direction, and it is why the conversion back will not return your original key.

### How do I get an attribute instead of a child element?

Prefix the key with @. So { "item": { "@sku": "PEN-01" } } writes <item sku="PEN-01"/> rather than a child element called sku. An element's own text goes under #text, which lets one element carry both attributes and content.

### What does an array become?

The key repeated once per entry, which is how XML expresses a list: three entries under "item" become three <item> elements side by side rather than a wrapper containing them. A top-level array has no name to repeat, so its entries are called item inside the root element.

### Why does my XML need a root element when my JSON did not?

Because XML allows exactly one top-level element and JSON allows any value at all. If your object has a single key, that key becomes the root and nothing is added. Anything else, an array or several keys, gets wrapped in a root element you can rename in the box above.

### Will the ampersands in my text break the output?

No. Ampersands and angle brackets in text are escaped, and quotes are escaped inside attribute values as well. An unescaped ampersand is the most common way a generated XML document turns out to be unparseable, so the output here is checked by parsing it back.

## Related tools

- [XML to JSON](https://filetity.com/xml-to-json): Convert XML to JSON, with attributes, namespaces and repeated elements handled.
- [JSON Formatter and Validator](https://filetity.com/json-formatter): Format, beautify, validate and read JSON, and find the line that broke it.
