Advertisement

JSON to XML Converter

Convert JSON to well-formed XML: objects become elements, arrays become repeated elements, @keys become attributes. Choose the root name and indentation.

Leave empty to use the single top-level key (here "library") as the root.
Used when an array sits at the top level or directly inside another array.

Plenty of older systems — SOAP services, RSS and sitemap tools, office formats, enterprise integrations — still speak XML while modern APIs return JSON. This converter maps JSON to well-formed XML: each object key becomes an element, each array item becomes a repeated element with the array's name, and special characters are escaped so the output always parses. Keys that start with @ can become attributes, following the widely used Goessner convention.

How to use this tool

  1. Paste your JSON.
  2. Leave the root name empty when the JSON has a single top-level key, or type a name to wrap everything in it.
  3. Choose the indentation, or "None" for compact single-line XML.
  4. Keep the @-attribute option on if your JSON came from an XML-to-JSON tool, then copy the result.

Formula

{"k": value} → <k>value</k>; {"k": [a, b]} → <k>a</k><k>b</k>; {"@id": "7"} → id="7"; null → <k/>.

Text is escaped (& → &amp;, < → &lt;, > → &gt;, and " → &quot; inside attributes). Keys that are not valid XML names, such as "first name" or "2nd", get underscores ("first_name", "_2nd") and are listed under the result. Colons and xmlns are renamed; this mapping does not create XML namespaces. Renamed-key collisions and unpaired surrogates are rejected.

Example

The sample library has one top-level key, so library becomes the root. Its "@name" turns into the attribute name="City Branch", and the two-item "book" array becomes two <book> elements with id attributes, each holding <title>, <author>, <year> and <available>. That is 11 elements in all: library, 2 books and 4 children per book.

Frequently asked questions

How are JSON arrays represented?

XML has no array type, so each item is written as a separate element with the array's key as its name. An array directly inside another array, or at the top level, uses the item name you choose (default <item>).

Can I get attributes instead of child elements?

Yes — prefix the key with @ in the JSON, for example {"@id": "7"}. A "#text" key sets the element's own text content next to its attributes.

Will converting back give me the same JSON?

Not always. XML stores everything as text, so 1965 and "1965" look the same, and a one-item array is indistinguishable from a single child. Keep a schema if you need an exact round trip.

Is the output valid XML?

The converter produces one root with escaped text. It removes forbidden XML 1.0 control characters with a note, rejects collisions, and preserves attribute whitespace with character references. XSD validation is separate.

Sources

Last updated: 2026-10-30

Advertisement