If the JSON is an object with one top-level key, that key is the root. Otherwise the output is wrapped in the root element, and top-level array entries use the item element. A "#text" key becomes the element's text.
XML appears here.How to use
Add JSON
Paste JSON into the JSON box, drop or upload a .json file, use Load URL, or press Try sample to load a small book catalog that uses @ attributes and an array.
Set names and options
Type a Root element and Array item element name, pick the Indent, and choose an attribute prefix. Tick or untick XML declaration and Self-close empty elements. The XML updates as you type.
Copy or download the XML
Press Copy above the XML pane, or Download .xml to save the file. Swap: XML to JSON opens the reverse converter.
Why JSON to XML Converter
- Set your own root and array item element names instead of fixed ones.
- Keys with a prefix you choose become attributes, and #text becomes element text.
- Indent with 2 or 4 spaces or tabs, or minify, with or without the XML declaration.
- Invalid names are renamed and several top-level keys are wrapped in one root, so the XML is well-formed.
JSON to XML mapping rules
The converter follows a small set of fixed rules. Knowing them makes it easy to shape your JSON so the XML comes out the way a receiving system expects.
The examples assume the default names, root for the root element and item for top-level array entries, with the @ attribute prefix and self-closing empty elements. The rules apply at every level of nesting.
| JSON | XML output |
|---|---|
| One top-level key: {"book": {...}} | <book>...</book> becomes the root |
| Several top-level keys: {"a": 1, "b": 2} | <root><a>1</a><b>2</b></root> |
| Nested object: {"price": {"amount": 9}} | <price><amount>9</amount></price> |
| Array value: {"tag": ["a", "b"]} | <tag>a</tag><tag>b</tag> |
| Top-level array: [{"id": 1}] | <root><item><id>1</id></item></root> |
| Attribute key: {"@id": "bk1"} | id="bk1" on the parent element |
| Text key: {"@lang": "en", "#text": "Dune"} | lang="en" on the element, with Dune as its text |
| Null: {"notes": null} | <notes/> |
| Invalid name: {"first name": "Ada"} | <first_name>Ada</first_name> |
What does not carry over from JSON to XML
JSON and XML describe data in different ways, so a few details change on the way across. Check these before you send the XML to a strict receiver, such as a SOAP service with a schema.
- Types: XML text is untyped, so numbers, booleans and strings all become text. A schema or the receiving code decides how to read them.
- Empty arrays produce no element at all, so the receiver cannot tell an empty list from a missing one.
- Attributes versus elements: only keys that start with the chosen attribute prefix become attributes. Everything else is an element, even if the receiving format expects an attribute.
- Namespaces: prefixes such as soap:Envelope are kept as part of the element name, but you have to add the xmlns attributes yourself, for example as an @xmlns:soap key.
- Order: elements follow the key order of your JSON, which matters when a schema requires a fixed sequence.