Skip to the JSON editor
JSON Formatter Viewer

JSON to XML

input.json

output.xml

The XML appears here.

or drop a .json file into the left pane

Waiting for input

The mapping

JSON and XML do not describe the same shapes, so any conversion has to pick a convention. This one uses the conventional mapping:

{
  "book": {
    "@id": "b1",
    "title": "Dune",
    "tag": ["scifi", "classic"]
  }
}

<book id="b1">
  <title>Dune</title>
  <tag>scifi</tag>
  <tag>classic</tag>
</book>
  • @name becomes an attribute.
  • #text becomes the element's text content, alongside its attributes.
  • An array repeats its parent's tag once per element.
  • An empty object or array becomes a self-closing element.

Escaping

Text content escapes &, <, and >. Attribute values additionally escape double quotes and newlines, so a value containing markup or a line break cannot break out of the document it is written into.

Where the mapping loses information

XML has no numbers, booleans, or null — everything is text — so type information is gone once converted. Combined with the array idiom, this means a round trip through XML is not guaranteed to reproduce the original JSON exactly. If the round trip matters, compare the before and after with the JSON diff rather than assuming.

Going the other way

XML to JSON reads this same convention, and uses the browser's own XML parser so entities, CDATA sections, and namespace prefixes are handled properly.

Common questions

How do I produce an attribute instead of a child element?

Prefix the key with @. {"book": {"@id": "b1"}} becomes <book id="b1"/>. This is the convention used by most JSON-to-XML mappings, and the XML to JSON converter reads it back the same way.

How are arrays represented?

XML has no array type, so the element name repeats. {"tag": ["a","b"]} becomes two <tag> elements. That is the standard idiom, and it is why an array of one is indistinguishable from a plain value when read back.

What about keys that are not valid XML names?

XML names cannot start with a digit and cannot contain most punctuation. Invalid characters become underscores, and a name starting with a digit is prefixed with one — so a b becomes a_b and 2024-total becomes _2024-total. The hyphen is kept, because it is legal everywhere except the first character.

How is null represented?

As an empty element carrying null="true". XML has no null, so the alternatives are an empty element — indistinguishable from an empty string — or an explicit marker. The marker is used so the distinction survives.

The rest of the toolkit

Same engine, same privacy — every page runs entirely in your browser.