JSON ↔ XML
Convert between JSON and XML.
Legacy SOAP endpoints and older enterprise systems still speak XML, while almost everything written this decade speaks JSON. Sooner or later you have a payload in the wrong shape and need a quick look at the other side. Paste it here, pick a direction, and read the result.
How it works
JSON → XML
The output starts with an XML declaration and wraps everything in a single <root> element, because XML allows only one top-level element while JSON can start with any value.
- Object keys become element names. A key that is not a valid XML name — one starting with a digit, or containing spaces or other illegal characters — is written as
<item>instead. - Arrays repeat the same tag.
{"tags":["a","b"]}produces two<tags>elements rather than an indexed wrapper. - Values are escaped.
<,>and&are converted to entities.nullbecomes an empty element. - Nesting is indented two spaces per level.
XML → JSON
Parsing uses the browser's own XML parser, so the input must be well-formed: every tag closed, one root element, and attribute values quoted. A syntax problem is reported as a format error rather than silently producing partial output.
Two behaviours worth knowing before you rely on the result:
| Detail | What happens |
|---|---|
| Attributes | Dropped. Only elements and text content are carried over. |
| Numbers and booleans | Returned as strings, because XML has no type information. |
| Repeated sibling tags | Collapsed into a JSON array under one key. |
| Leaf elements | Become the element's text content. |
That means the round trip is not always lossless. Convert to sketch a structure quickly, but check the output against your schema before shipping it.
Terms explained
- Root element
- The single outermost XML element. This tool names it root when converting from JSON, since JSON has no equivalent requirement.
- Well-formed XML
- XML that follows the syntax rules — one root, every tag closed, quoted attribute values. Required before parsing can succeed.
- XML entity
- An escape sequence such as < or & used to write characters that would otherwise be read as markup.
- Attribute
- Extra data written inside a tag, like <user id="1">. XML supports it, JSON has no direct equivalent, so it is not carried over here.
- Pretty print
- Output formatted with line breaks and two-space indentation for readability, rather than one long line.
Frequently asked questions
Why did my numbers turn into strings after XML → JSON?
XML stores everything as text and carries no type information, so the parser cannot tell 42 the number from "42" the string. Cast the fields you need on your side after converting.
Where did my XML attributes go?
The converter reads element structure and text content only, so attributes are not included in the JSON output. If attributes carry meaningful data, restructure them as child elements before converting.
Why is everything wrapped in a root element?
XML permits exactly one top-level element, while a JSON document can be an object, an array, or a bare value. Adding root keeps the output valid for any input.
How are JSON arrays represented in XML?
As repeated elements with the same name. There is no index attribute, so ordering is positional — the order in the XML is the order from the array.
Can I convert back and forth without losing anything?
Not reliably. Attributes are dropped, types become strings, and irregular keys are renamed, so treat the output as a starting point rather than a guaranteed equivalent.
Tell us what went wrong and we'll fix it fast. (Leave an email if you'd like a reply.)