Shard Tools

JSON to XML

Turn JSON into well-formed XML in your browser, with escaping and element naming handled correctly.

Maintained by Roshan.

Use JSON to XML

Converts between XML and JSON in this tab using the browser's own XML parser. Nothing is uploaded, which matters for the configuration files and invoices these formats usually carry.

How the two shapes are mappedAttributes become keys prefixed with @, mixed text sits under #text, and repeated sibling tags collapse into an array. Values stay strings: turning 0123 into a number would quietly break postcodes and version numbers.

Explore developer and data tools

Find related browser-local tools for nearby tasks without starting another search.

Browse all developer and data tools

About JSON to XML

Generating XML from JSON is easier than the reverse, because XML can express everything JSON can and more. The difficulties are narrower and more mechanical: XML has strict rules about what an element may be called, and a set of characters that must be escaped or the document will not parse. JSON has neither restriction. A key containing a space, a leading digit, or an ampersand is perfectly ordinary JSON and completely illegal as an XML tag name, and a value containing a less-than sign will break the document unless it is escaped. Most quick converters ignore both problems and emit output that no XML parser will accept. This one repairs names and escapes values, and shapes the result so that feeding it back through the XML to JSON converter returns what you started with.

Work through the input

  1. The JSON is parsed first, so a syntax error is reported with the parser's own message rather than producing half a document.
  2. An object with a single top-level key uses that key as the root element, since it already names itself. Anything else is wrapped in a root element, because XML permits exactly one.
  3. Keys prefixed with @ are written as attributes and a #text key becomes the element's text content, mirroring the convention the reverse converter reads.
  4. Arrays repeat the parent tag rather than inventing a wrapper or numbered elements. This is the shape that survives a round trip back to JSON.
  5. Ampersands, angle brackets and quotes are escaped in both text and attribute values, so the output is well-formed rather than merely plausible.

When json to xml is useful

Feeding an API that only accepts XML

Wrap your payload in a single top-level key named after the expected root element, and use @ keys for anything the endpoint expects as an attribute.

Producing a configuration file

Many older tools read XML configuration exclusively. Building the structure in JSON first is usually quicker and less error-prone than writing tags by hand.

Check the output

Questions about JSON to XML

How do I control the root element name?

Give your JSON a single top-level key. That key becomes the root. Objects with several top-level keys are wrapped in a generic root instead.

How do I produce attributes rather than child elements?

Prefix the key with @. A key of @id becomes an id attribute on the enclosing element.

What happens to a key with a space in it?

The space becomes an underscore, because XML element names cannot contain spaces. Emitting the invalid name would produce a document no parser accepts.

Does the output round-trip?

Yes. The @ and #text conventions and the array shape are all chosen so the XML to JSON converter returns the original structure.

Is anything sent to a server?

No. The JSON is parsed and the XML built entirely in this tab.

Related tools

XML to JSON

Convert XML to readable JSON in your browser. Attributes, repeated tags and mixed content are all handled predictably.

JSON Formatter and Validator

Format, minify, and validate JSON locally in your browser. Inspect keys, values, nesting depth, and root type without sending private API data to a server.

JSON to CSV Converter

Convert JSON objects to UTF-8 CSV in your browser. Union columns, quote values, and protect formula-like strings.

JSON to INI

Turn JSON into an INI configuration file in your browser, with objects becoming sections.

JSON to HTML Table

Turn a JSON array into a clean HTML table in your browser, with markup in the data escaped safely.