Home › File & PDF Tools › JSON to XML Converter

JSON to XML Converter

Our free JSON to XML converter turns JSON data into clean, readable XML right in your browser — and it converts back the other way too. Paste your JSON, pick a root element name, indentation, and empty-element style, and download a real .xml file. Nothing is uploaded to any server, there is no sign-up, and there is no watermark.

Your data stays on your device. It is converted in your browser and never uploaded anywhere.

How it works

JSON and XML describe the same kind of data — named values grouped into objects — but they spell it differently. JSON writes an object as curly braces with quoted keys, while XML writes it as tags with an opening and a closing part. This tool walks through your data one value at a time and rewrites it in the other spelling, so a setting, an API response, or a product list can move between a modern web service that speaks JSON and an older system, feed, or config file that expects XML.

Objects become elements. A JSON object such as {"name": "Alice", "age": 30} becomes <root><name>Alice</name><age>30</age></root>, with each key turning into a tag name and each value turning into the text inside it. Numbers and true/false values are written as plain text — 30 becomes <age>30</age> — and a null value becomes an empty element, because XML has no built-in null. Nested objects simply nest: an object inside an object becomes an element inside an element, as deep as your data goes.

Arrays become repeated elements, because XML has no array brackets. The JSON {"tags": ["reader", "hiker"]} becomes <tags>reader</tags><tags>hiker</tags>, with one element per item, in the same order. If an array sits at the very top of your JSON, each item is wrapped in an <item> element under your root element, so the list still has a clear shape. Two special key conventions cover the parts of XML that JSON has no spelling for. A key that starts with @ becomes an attribute: {"book": {"@id": "7", "#text": "Dune"}} becomes <book id="7">Dune</book>. A key called #text holds the text content of an element that also has attributes, so the title and the id can live together in one element.

You control the shape of the output. The root element name is root by default, but you can rename it to match the system you are feeding — order, catalog, config, or anything else. Indentation offers 2 spaces, 4 spaces, a tab, or compact output with no extra whitespace at all, which is the smallest file when size matters. Empty elements can be self-closing (<note />) or paired (<note></note>), and the optional XML declaration adds the <?xml version="1.0" encoding="UTF-8"?> line that some strict parsers expect at the top. Key order can stay as you wrote it or be sorted A to Z, which makes comparing two files much easier.

Before anything is converted, the tool validates your input. If your JSON has a missing comma, an unclosed quote, or an extra bracket, it stops and shows a friendly message with the exact line and column where the problem is — for example, "line 3, column 12" — instead of producing broken XML. The reverse mode validates your XML the same way with the browser's built-in XML parser: a mismatched tag or a stray & is reported in plain words, and attributes come back under @ keys, repeated elements come back as JSON arrays, and mixed text is kept under #text, so a round trip from JSON to XML and back keeps your data intact. Special characters are escaped properly in both directions: & becomes &amp;, < becomes &lt;, and quotes inside attributes become &quot;.

JSON object → XML element · JSON array → repeated elements · "@key" → attribute · "#text" → element text · XML → JSON reverses each rule

Everything happens in your browser. Your data is never uploaded, so API keys, customer records, and private configuration files stay private, and the tool works offline once the page has loaded. Copy the result to paste it into another program, or download it as a .xml file (or a .json file in reverse mode) named after your root element.

Worked example

Suppose you have a small customer record in JSON and an older ordering system that only accepts XML:

{"name": "Alice", "age": 30}

Step 1: paste the JSON into the input box, with the direction on JSON to XML and the root element name on root.
Step 2: leave the indentation on 2 spaces and empty elements on self-closing, and click Convert.
Step 3: the output shows <root> on the first line, then <name>Alice</name> and <age>30</age> indented underneath, and </root> at the end. The page reports 2 elements and the size of the result in bytes.
Step 4: click Download .xml to save the file as root.xml, ready to hand to the ordering system.

Now try the conventions on a richer record. Paste {"book": {"@id": "7", "#text": "Dune"}, "tags": ["reader", "hiker"]} and convert it. The book's @id becomes the attribute id="7" on the <book> element, #text becomes the title Dune inside it, and the two tags become two repeated <tags> elements — <tags>reader</tags> followed by <tags>hiker</tags>. Switch the direction to XML to JSON, paste that XML back in, and you get the same JSON you started with, attributes and arrays included.

If you paste JSON with a mistake — say {"name": "Alice" "age": 30} with the comma missing — the tool does not guess. It shows a message like "Check line 1, column 18: a comma is expected here," so you can fix the one character and convert again.

FAQ

Is my JSON uploaded to a server?

No. Your JSON is parsed and converted entirely in your browser. Nothing is uploaded anywhere, so private API responses, configuration files, and customer data stay on your own device.

How do I write an attribute in JSON?

Start the key with @ and the value becomes an XML attribute instead of a child element. For example, {"book": {"@id": "7", "title": "Dune"}} becomes <book id="7"><title>Dune</title></book>. The @ is removed in the XML output.

How are arrays converted to XML?

Each item in a JSON array becomes a repeated element with the same tag name, in the same order. For example, {"tag": ["red", "blue"]} becomes <tag>red</tag><tag>blue</tag> inside the parent element, so no item is lost and the order is preserved.

Can I convert XML back to JSON?

Yes. Switch the direction to XML to JSON and paste your XML. Attributes come back under keys that start with @, repeated elements come back as JSON arrays, and mixed text is kept under the #text key, so a round trip keeps your data intact.

What happens if my JSON has an error?

The tool checks your JSON before converting and shows a friendly message with the exact line and column where the problem is, for example a missing comma or an unclosed quote. Fix that spot and convert again — no broken XML is produced.