๐Ÿ“‘XML to JSON Converter (Both Ways)

Convert both ways and see what each pass drops

Mapping rules this tool uses

XML sideJSON sideRound trip
Element nameObject keyKept
Attribute attr="v""@attr": "v"Kept
Text-only elementString valueKept
Attributes plus textText under "#text"Kept
Two or more same-name siblingsArrayOne stays scalar
Empty element <a/>Empty string ""Back to empty element
Namespace prefixLiteral part of the keyText only
Comments and PIsNothingDropped
CDATAPlain textMarker dropped
Mixed contentText merged into #textPosition lost
Numbers and booleansRead as stringsNo typing

You Might Also Need

Converting between XML and JSON in both directions

Pick a direction, paste the source, and you get the converted output, its size and a list of what this particular conversion lost. The default sample contains a comment, two same-name siblings and an empty element, so you can see how losses are reported straight away.

XML parsing goes through the browser DOMParser, and the mapping follows the table above: attributes become keys prefixed with @, loose text becomes a #text key, and repeated siblings become an array. The important premise is that this conversion is not lossless. XML carries comments, processing instructions, CDATA markers and the position of mixed text, and a JSON object has nowhere to put them.

Going the other way, numbers and booleans turn into text and a one-item array flattens into a single element. As of October 2026 there is no single standard XML-to-JSON mapping, so every tool picks its own rules and another converter may disagree with this one. Schema validation and XSLT transformation are not supported.

Frequently Asked Questions

Will a round trip give me the original back?

No. Comments, processing instructions, the CDATA distinction and the position of mixed text are all lost, and a one-item array flattens to a scalar. The output panel lists what this conversion dropped and how many of each.

What happens when an attribute and a child element share a name?

Attributes move to keys prefixed with @, so identical names never collide. XML element names cannot start with @, which keeps the two apart.

Does it convert numeric text into real numbers?

It does not. XML values carry no type, so a string that looks like a number cannot be told apart from a real number, and everything is read as a string.