JSON to XML

Convert JSON to well-formed XML with attributes and a single root.

Runs in your browser Instant No sign-up
Attribute prefix
Indent
JSON
XML
Reverse

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the JSON to XML converter

  1. Paste, drop or open JSON in the left pane. Invalid JSON is reported with its line and column.
  2. Choose the Attribute prefix: @id, @_id or _id. Keys with that prefix become attributes.
  3. Set the Root element name (default root) and, if needed, turn on Always wrap in root.
  4. Turn XML declaration on or off and choose the Indent, including Minify.

Example

{
  "catalog": {
    "@updated": "2026-09-27",
    "book": [
      { "@id": "bk101", "title": "Moby Dick" },
      { "@id": "bk102", "title": "LOTR" }
    ]
  }
}

becomes

<?xml version="1.0" encoding="UTF-8"?>
<catalog updated="2026-09-27">
  <book id="bk101">
    <title>Moby Dick</title>
  </book>
  <book id="bk102">
    <title>LOTR</title>
  </book>
</catalog>

catalog is the only key, so it becomes the root element. The book array becomes repeated <book> elements, and the @ keys become attributes.

Mapping rules

JSON XML
"title": "Moby Dick" <title>Moby Dick</title>
"@id": "bk101" id="bk101" attribute
"#text": "Hello" next to attributes Element text: <p class="x">Hello</p>
Array value Repeated elements with the key’s name
Top-level array [1, 2] <root><item>1</item><item>2</item></root>
null Self-closing element, e.g. <empty/>
true, numbers Text: <flag>true</flag>

Root element rules

Input Result
{"catalog": {…}} <catalog> is the root
{"a": 1, "b": 2} Wrapped: <root><a>1</a><b>2</b></root>
[1, 2] Wrapped, items named item
{"a": 1} with Always wrap in root and root data <data><a>1</a></data>

An invalid Root element name such as 1x is rejected with "1x" is not a valid XML element name.

Invalid keys

Keys that aren’t valid XML names are reported together, for example Keys that aren't valid XML element names: "first name". Element names must start with a letter or underscore and may contain letters, digits, -, _ and ..

Tips

  • Turn off XML declaration when the XML will be embedded in another document or sent as a fragment.
  • Use Minify before placing the XML in a request body or a single-line config value.
  • JSON has no order for object keys, but the converter writes elements in the order they appear in your input, so you control the element order.
  • If a system expects a specific schema, compare a real sample with the output and rename keys in the JSON first; the converter doesn’t know about XSDs.

Convert back with XML to JSON — the Reverse button opens your result there — or pretty-print existing XML with the XML Formatter. For configuration files, JSON to YAML is often a better fit than XML.

Frequently asked questions

Is my JSON uploaded?

No. The conversion runs in your browser and nothing is uploaded.

How do I create XML attributes?

Prefix the key with the character set in Attribute prefix. With the default @, {"book": {"@id": "bk101"}} becomes <book id="bk101"/>. Use a #text key for the element's text when it also has attributes.

When is a root element added?

XML must have exactly one root element. If your JSON is an object with one key whose value is not an array, that key becomes the root. Otherwise, such as an array or an object with several keys, everything is wrapped in the element named in Root element. Always wrap in root forces the wrapper.

Why do I get an error about element names?

XML element names can't contain spaces or start with a digit, so keys like "first name" or "1x" can't become elements. Rename those keys, or convert them to attributes if your schema allows it.

What happens to null and big numbers?

null becomes a self-closing element named after its key: "note": null gives <note/>. Numbers are written as they appear in the JSON, so large IDs like 9007199254740993 are kept exactly.

Last updated