json:yaml

JSON to XML converter

Convert JSON to XML: objects become nested elements, arrays repeat their parent tag, and text is escaped. Key names that are not valid XML names are sanitised.

JSON
XML

      
Paste JSON to convert.

Conversion happens in this browser tab. Nothing is uploaded, logged, or stored.

The mapping

There is no single official way to represent JSON as XML, because the two models do not line up. XML has attributes and ordered mixed content; JSON has neither. This converter uses the most common and most predictable convention:

  • The document gets a single <root> element, because XML requires exactly one root and JSON does not have one.
  • Each object key becomes an element with that name.
  • Arrays repeat the parent element once per item, rather than inventing a wrapper.
  • Scalars become element text, with &, < and > escaped.
  • null becomes a self-closing element.
  • Nothing becomes an XML attribute. Attributes would be ambiguous on the way back.

Key names that are not valid element names

XML element names are restricted in ways JSON keys are not. A name must start with a letter or underscore and may not contain spaces, slashes, or most punctuation. Keys that break those rules are sanitised: invalid characters become underscores, and a leading digit gets an underscore prefix.

JSON keyXML element
"first name"<first_name>
"2026"<_2026>
"user-id"<user-id> — hyphens are legal
"price($)"<price___>

Sanitising is lossy: two different keys can collapse to the same element name. If your keys contain punctuation, rename them before converting rather than after.

Round-tripping

Converting JSON to XML and back does not always return the original. Type information is the main casualty — XML text has no types, so the number 3 and the string "3" are written identically and come back as whichever the reverse converter guesses. An array of one element also becomes indistinguishable from a single value, because both are one repeated element.

If you need a faithful round trip, keep JSON as the source of truth and generate the XML as an output artifact. The reverse tool, XML to JSON, documents what it cannot recover.

Your document stays local

XML is where the payments and procurement world still lives: invoices, purchase orders, SOAP envelopes, supplier records. Documents that carry counterparty names, bank details, and prices you are contractually obliged to keep confidential.

Converting one here does not disclose it. The transformation happens in your browser, with no upload and no server-side processing of your content at any point.

Questions people ask

Why is everything wrapped in a root element?
XML requires exactly one root element and JSON does not have one. A wrapper called root is added so the output is a well-formed XML document.
Are any values written as XML attributes?
No. JSON has no concept of attributes, so choosing which keys become attributes would be arbitrary and would break round-tripping. Everything becomes an element.
What happens to keys with spaces or punctuation?
They are sanitised, because XML element names cannot contain them. Invalid characters become underscores and a leading digit gets an underscore prefix. This is lossy — rename such keys before converting.
Can I convert the XML back to the original JSON?
Not exactly. XML text has no types, so 3 and "3" become identical, and a one-element array is indistinguishable from a single value.
How are arrays represented?
The parent element is repeated once per item, rather than adding an artificial wrapper element. This is the most common XML convention.