JSON to XML converter

Convert JSON to well-formed XML in your browser. Invalid element names rewritten, declaration optional. Nothing is uploaded.

About this converter

Converting JSON to XML usually means you are feeding something older than the system that produced your data: a SOAP endpoint, a legacy import, a billing provider whose API has not changed since 2009. The conversion itself is mechanical, but there are two rules XML enforces that JSON does not, and ignoring either produces a document the receiving parser rejects.

The first is element naming. A JSON key can be any string at all - it can start with a digit, contain spaces, be an empty string, or hold punctuation. XML element names cannot. This converter rewrites offending characters to underscores and prefixes an underscore where a name starts with a digit, so the result is always well-formed rather than almost-valid.

The second is the root element. An XML document must have exactly one, and a JSON array has none to offer. A top-level array therefore gets wrapped, and the converter tells you it did rather than leaving you to discover it when the parser complains. You can wrap objects too, which is usually what a schema expects.

Special characters in values are escaped as entities - ampersands, angle brackets and quotes - because an unescaped ampersand is the single most common reason a generated XML file fails to parse.

You can include or omit the XML declaration and pick the indentation, including no indentation for the smallest possible payload when the document is machine-to-machine and nobody will read it.

Everything happens in your browser. No upload, which matters because the JSON you are converting for a billing or payroll integration is rarely the kind you would paste into an unknown server.

Frequently asked questions

Why did my key get renamed?
XML element names cannot contain spaces or most punctuation, and cannot begin with a digit. Offending characters become underscores so the output actually parses.
Why was my array wrapped in a root element?
XML requires exactly one root element, and a top-level JSON array does not provide one. Wrapping is the only way to produce a valid document.
Can I produce attributes instead of child elements?
Keys prefixed with @_ become attributes, which is the same convention the XML to JSON converter emits. Round-tripping through both tools preserves them.

Related converters