DT Dev Tools

JSON to XML Converter

Convert JSON to well-formed XML online with attributes, repeated elements for arrays, a root element and indentation. Free, instant and private in your browser.

πŸ”’ Runs entirely in your browser β€” nothing is uploaded

Advertisement

Turn JSON into well-formed XML

When an older API, a SOAP endpoint, a payment provider or a configuration system only accepts XML, you need to turn the JSON your application already produces into a valid document. This JSON to XML converter does exactly that. Object keys become element names, nested objects become nested elements, arrays become repeated elements with the same name, and strings, numbers and booleans become text content. Special characters such as < and & are escaped automatically, and null values become empty self-closing elements.

Keys that are not valid XML names are made safe: spaces and symbols are replaced with underscores and names that start with a digit get a leading underscore. The output is indented with two spaces, four spaces or tabs, and an optional <?xml version="1.0" encoding="UTF-8"?> declaration is added at the top.

Attributes, text and the root element

JSON has no attributes, so the converter uses a simple convention: keys that start with the attribute prefix β€” @ by default β€” are written as attributes on their parent element, and a #text key sets the element's text content alongside those attributes. This is the same convention the XML to JSON converter produces, so documents survive a round trip. Every XML document needs exactly one root element: if your JSON already has a single top-level key holding an object, that key becomes the root; otherwise everything is wrapped in the root name you set.

Practical tips

Check the receiving system's schema before sending the result: element order, required wrappers and namespaces are often strict in XML, and JSON key order is preserved as written. Add namespace declarations as attributes, for example "@xmlns": "http://example.com/ns". If a list must always appear as a wrapper element with children, model it explicitly as {"items": {"item": [...]}}. All processing happens locally, so payloads containing customer data stay on your machine.

How to use

  1. Paste JSONPaste a JSON object or array, or load the sample.
  2. Set optionsChoose the root element name, attribute prefix, indentation and XML declaration.
  3. Copy the XMLCopy the result or download it as a .xml file.

Frequently asked questions

How do I create XML attributes from JSON?
Prefix the key with @ (or the prefix you set). {"book": {"@id": 7, "title": "Dune"}} becomes <book id="7"><title>Dune</title></book>.
What happens to JSON arrays?
Each array item becomes a repeated element with the key's name. A top-level array is wrapped in the root element with one <item> per entry.
Why is a root element added?
An XML document must have exactly one root element. If your JSON has several top-level keys, is an array or is a plain value, it is wrapped in the root element name you choose.
Is my JSON uploaded?
No. The XML is built locally in your browser.
Advertisement