Developer Tools

JSON to XML Converter

Turn JSON data into clean, well-formed XML. Nested objects become nested elements, arrays become repeated or wrapped elements, and keys that start with @ can become attributes. Everything runs in your browser.

  • Runs in your browser
  • No sign-up
  • Free to use

How to use JSON to XML

  1. Paste JSON into the left pane or open a .json file.
  2. Set the root element name, how arrays should be written and the indentation.
  3. Select Convert to XML.
  4. Copy the result or download it as an .xml file.

JSON to XML features

Nested structures

Objects and arrays of any depth are converted, including arrays inside arrays.

Two array styles

Repeat the element for each item, or wrap the items in a parent element.

Attributes and text

Keys starting with @ become attributes and #text becomes the element's text, following a common convention.

Always well-formed

Special characters are escaped and keys that are not legal element names are corrected.

Precise error messages

Invalid JSON is reported with the line where parsing failed.

Private

The conversion happens locally; your data is not uploaded.

When to use JSON to XML

  • Feeding data from a JSON API into a system that only accepts XML.
  • Creating test fixtures for SOAP services or XML parsers.
  • Preparing an XML import file for an older application.
  • Seeing how a JSON structure would look as markup.

JSON to XML FAQ

How are JSON arrays written in XML?

XML has no array type, so there are two conventions. With “repeat the element”, {"book": [a, b]} becomes two <book> elements side by side. With “wrap items”, it becomes one <book> element containing <item> children. Choose the one the receiving system expects.

How do I create XML attributes?

Prefix the key with @. {"book": {"@id": "b1", "title": "Dune"}} becomes <book id="b1"><title>Dune</title></book>. Use the key #text for the text content of an element that also has attributes. Turn the option off to treat such keys as ordinary elements.

What happens to keys that are not valid XML names?

Element names may not contain spaces or most punctuation and may not start with a digit. Invalid characters are replaced with underscores and a leading underscore is added where needed, so “2nd place” becomes <_2nd_place>.

How are null, true and numbers handled?

null becomes an empty element such as <author/>. Booleans and numbers are written as text, because XML has no data types of its own; a schema on the receiving side decides how they are interpreted.

Why does XML need a root element?

A well-formed XML document has exactly one top-level element. If your JSON is an object with a single key, that key becomes the root. Otherwise the name you enter in the Root element field is used.

Can I convert the XML back to the same JSON?

Mostly. Structure and text survive, but types do not: after a round trip, the number 1965 comes back as the string "1965" unless the reverse converter is told to detect numbers. A single-item array also looks the same as a single element in XML.

Mapping JSON onto XML

JSON and XML describe data with different building blocks. JSON has objects, arrays, strings, numbers, booleans and null. XML has elements, attributes and text. There is no single correct translation between the two, only conventions, and a converter is useful to the extent that its conventions are predictable and adjustable.

The straightforward part is nesting. An object becomes an element, its keys become child elements, and a string or number becomes text inside the element. Arrays are where the models diverge. XML expresses a list simply by repeating an element, so the natural rendering of a list of books is several book elements in a row. Some schemas prefer a container, books, holding the individual entries. Both are common, and the option lets you match whatever the consuming system was built for.

Attributes have no counterpart in JSON at all. The widely used workaround is a naming rule: keys beginning with @ are treated as attributes of the enclosing element, and a key called #text carries the element's own text. The same rule is applied in reverse by many XML-to-JSON converters, which makes round trips possible.

Whatever conventions you choose, the output must be well-formed, or an XML parser will reject the whole document. That means one root element, properly nested tags, legal names, and the characters <, > and & written as entities inside text. The converter guarantees these, including for awkward input such as keys with spaces or values containing markup.

Other useful tools