JSON to XML Converter
Convert JSON to well-formed XML with automatic root-element wrapping and indentation. Paste JSON, get valid XML for SOAP, RSS or config files. Nothing uploaded.
Worked examples
- An object with one top-level key
When the JSON already has a single top-level key, it becomes the XML root element directly — no extra wrapper tag needed.
- An object with multiple top-level keys
XML documents can only have one root element, so a JSON object with several top-level keys is wrapped in a <root> element automatically.
- Repeated array items become repeated sibling tags
A JSON array is the mirror image of XML's repeated-sibling pattern, so each array entry is written as its own <item> tag.
What this converter does
This tool parses JSON and writes it back out as well-formed XML, applying the mirror image of the rules an XML-to-JSON converter uses: object keys become tags, arrays become repeated sibling elements, and keys starting with @_ become attributes. Because XML requires exactly one root element and JSON objects can have any number of top-level keys, the converter also decides — automatically and predictably — whether your data needs a wrapper <root> tag.
When you need it
- Producing XML for a SOAP request, an RSS feed, or a legacy system that only accepts XML, starting from JSON data your code already has.
- Converting a JSON config object into an XML-based config file a tool requires.
- Quickly seeing what a piece of JSON data "looks like" as XML while migrating an integration from one format to the other.
Rules the converter applies
- If the JSON object has exactly one top-level key, that key becomes the XML root element directly —
{"user": {...}}becomes<user>...</user>. - If the JSON object has more than one top-level key, the whole object is wrapped in a
<root>element, since XML can't have multiple root elements the way JSON can have multiple top-level keys. The same wrapping applies when the single top-level key holds an array ({"a": [1, 2]}would otherwise repeat<a>as two roots), and a top-level JSON array becomes<root>with one<item>per entry. - Arrays become repeated sibling tags.
{"items": {"item": ["a", "b"]}}becomes<items><item>a</item><item>b</item></items>— one tag per array entry, using the array's own key as the tag name. - Keys prefixed with
@_become attributes on their parent element rather than child tags, mirroring how this hub's XML-to-JSON converter represents attributes — so a round trip through both tools returns you to equivalent data. - Output is indented using the space count you choose, for readability; XML itself doesn't require indentation, so this is purely cosmetic.
Things to check after converting
- XML names must start with a letter,
_or:and contain only letters, digits,_,-,.or:. A JSON key such as"first name"or"1st"can't be an element name, so the tool stops with an error naming the key instead of producing XML that no parser would accept. Rename the key and convert again. - An array nested directly inside another array (
[[1, 2], [3]]) has no XML equivalent and is rejected for the same reason; give each inner array a key. - Values are written as XML text content, always as strings — booleans become the literal text
trueorfalse, and numbers are written in their JavaScript decimal form. - An empty object becomes an empty element (
<o></o>) andnullbecomes a self-closing one (<n/>), while an empty array produces no element at all; confirm that is what the system receiving the XML expects, since some XML parsers treat an empty tag and a missing tag differently. - A key named
"#text"is written as the element's own text content ({"note": {"@_lang": "en", "#text": "hi"}}becomes<note lang="en">hi</note>); any other key, including"text", becomes an ordinary child tag. Text characters such as&,<and>are escaped automatically.
Limits
Input is capped at 2 MB. This converter doesn't add an XML declaration (<?xml version="1.0"?>) or a DOCTYPE — add one yourself if the consuming system requires it, since not every XML context does.
Frequently asked questions
- Is my JSON uploaded anywhere?
- No. The conversion runs entirely in your browser; nothing is sent to a server.
- Why did my JSON get wrapped in a <root> tag?
- XML requires exactly one root element. If your JSON object has more than one top-level key, they're wrapped in <root> so the output is valid XML.
- What if a JSON key is not a valid XML name?
- The tool stops and names the key. XML element and attribute names must start with a letter, underscore or colon and cannot contain spaces, so a key like "first name" or "1st" has to be renamed before converting.
- How are JSON arrays represented?
- Each item in the array is written as a repeated sibling tag using the array's key as the tag name.
- How are JSON keys starting with @ handled?
- A key like "@_id" (the prefix is @_, not just @) is written as an XML attribute on its parent element rather than as a child tag.