LocalToolkit
HomeData Converters › JSON to XML Converter

JSON to XML Converter

Attribute and text conventions respected, and every value escaped correctly.

🔒 Runs in your browser. Nothing is uploaded — verify it in the network panel, or disconnect and try again.

There is no canonical mapping, so agree on one

JSON and XML are not isomorphic, and no standard defines how to move between them. Every tool invents its own conventions, which means two systems can agree on the data and still fail to read each other's XML. The convention used here is the one most JSON-to-XML tools converge on, and it is worth stating explicitly so both sides can implement it.

JSONXMLReason
{"@id": "7"}<a id="7"/>A key starting with @ becomes an attribute
{"#text": "hi"}<a>hi</a>The #text key becomes element content
{"a": [1, 2]}<a>1</a><a>2</a>An array becomes repeated elements, using the key as the tag
{"items": [1, 2]}<item>1</item><item>2</item>A plural key is singularised for the repeated element
{"a": null}<a/>Absent value becomes an empty element
{"a": true}<a>true</a>XML has no boolean type — everything is text

What is lost in both directions

The escaping you cannot skip

Five characters must be escaped in XML content and attributes: & as &amp;, < as &lt;, > as &gt;, and quotes. The ampersand must be replaced first, otherwise the entities you just generated get escaped again and render as visible source. Also note that XML has no &nbsp; — the named entities you may know from HTML are not available unless a DTD declares them, so use numeric character references.

Verbosity, and why it matters at scale

For the same data, XML typically runs two to three times the size of JSON, because every value needs an opening and a closing tag. That overhead matters for mobile payloads and for log storage. XML retains real advantages — document validation against a schema, mature tooling for documents rather than data, and a long history in enterprise and publishing systems — but for new APIs carrying records, JSON is the smaller and simpler choice.

How to use it

  1. Paste JSON.
  2. Set the root element name — root by default.
  3. Convert and check attribute placement.
  4. Validate against the XML schema the receiving system expects.

Worth knowing

  • Keys beginning with @ become attributes; #text becomes element content.
  • Arrays become repeated elements; plural keys are singularised for the tag name.
  • XML has no native boolean or number type — everything is character data.
  • XML has no named entities without a DTD, so use numeric references.

Limitations

  • Mixed content — text interleaved with child elements — cannot be represented.
  • Namespace prefixes and URIs are not generated.
  • Comments and processing instructions in the source JSON do not exist to preserve.
  • All type distinctions are lost; numbers and strings become indistinguishable text.

Frequently asked questions

How do I represent XML attributes in JSON?
Prefix the key with @, so <a id="7"/> becomes {"@id": "7"}. This tool reads and writes that convention in both directions.
Why did my numbers become strings?
Because XML has no numeric type — every value is character data. A consumer that needs a number must parse the text itself, and a boolean becomes the literal text true or false.
Can mixed content round-trip?
No. <p>Hello <b>world</b>!</p> interleaves text and elements in a way JSON cannot express. Document-oriented XML should stay XML.
Which is better, JSON or XML?
For record-oriented APIs over HTTP, JSON: smaller, simpler, and unambiguous about types. For document publishing, schemas and mature enterprise tooling, XML still has the stronger ecosystem.
Related tools
XML to JSON ConverterJSON Formatter & ValidatorJSON to YAML ConverterHTML Entity Encoder / DecoderJSON MinifierJSON to CSV Converter
Keep reading
How browser-only processing worksAll Data Converters toolsEvery tool on the site