This tool runs entirely in your browser. Nothing you paste is uploaded.
How you can check →XML to JSON
Convert XML to JSON in your browser, with the mapping rules written down rather than assumed — including what cannot be represented and why.
The JSON appears here.
No network activity while you use this tool Show the numbers
- Requests to any other server
- 0
- Requests since you started typing
- —
Counted live by your browser's own Performance Timeline — the same data the DevTools Network panel reads. It cannot see what a browser extension does, and it is not meant to replace checking for yourself: here is how, in thirty seconds .
There is no canonical XML-to-JSON mapping
This is the first thing worth knowing, and most converters do not say it. XML can express things JSON has no vocabulary for: attributes distinct from content, text interleaved between child elements, sibling order, namespaces, and the difference between an element that is absent and one that is empty. Any conversion therefore picks a convention, and the established conventions — compact, Badgerfish, Parker — produce different JSON for the same document.
This tool implements the compact convention, which is the most widely used, and tells you when it has had to throw something away.
The rules, in full
-
An element with only text becomes that text:
<name>Ada</name>becomes"name": "Ada". -
An empty element becomes
null.<a/>and<a></a>are treated identically, because XML gives no reason to separate them. -
Attributes become properties prefixed with
@, so<user id="1">gives"@id": "1". -
Text alongside attributes or children goes into
#text. - Repeated child elements collapse into an array, in document order.
-
Namespace prefixes are kept verbatim —
soap:Bodystayssoap:Body, andxmlns:*declarations stay as ordinary attributes. Resolving prefixes to URIs would change every key in the document.
The repeated-element trap
A list with one entry and a list with two entries map to different JSON shapes — an object in the first case, an array in the second — because nothing in the XML says the element repeats. Code that reads the result then works in testing and fails on the day an order has a single line item. Turning on always use arrays makes every child element an array so the shape depends on the schema rather than the data.
Mixed content
<p>before<b>bold</b>after</p> has text on both sides of a child element.
JSON cannot record where the text sat relative to the child, so the text is joined into
#text and the position is lost. The conversion warns when this happens rather
than letting you discover it later.
What is not supported, on purpose
DTDs are skipped and entities declared in them are not resolved, so a document relying on a custom entity gets a clear error naming it instead of a silently missing character. Schema validation is out of scope. Silently ignoring a construct is worse than saying it is unsupported, because it produces output that looks complete and is not.
Error messages
Parse failures report a line and a column, and name what was actually wrong: a closing tag that does not match the element still open and where that element started, an attribute with no quotes, a duplicate attribute, an unterminated comment or CDATA block. Browsers' own XML parsers report these inconsistently and often unreadably, which is why this page uses its own.
Frequently asked questions
- Is there a standard way to convert XML to JSON?
- No, and that is the honest answer any converter should give. XML has attributes, mixed content, ordered siblings and namespaces; JSON has none of those. Several conventions exist and they disagree with each other. This tool uses the widely used compact convention, shows you its rules, and warns you where information is lost.
- Why did one <item> become an object and two become an array?
- Because XML has no way to say 'this element repeats'. With one child the converter cannot tell a list from a single value. That means the shape of the output depends on the data, which breaks anything downstream expecting a fixed shape — so there is an 'always use arrays' option that removes the ambiguity.
- Why does cause an error?
- XML predefines only five entities: < > & " and '. Everything else, including , must be declared in a DTD. This tool does not read DTDs, so it reports the unknown entity and suggests the numeric form —   — rather than silently dropping the character.
- Are attributes and text kept?
- Yes. Attributes become properties prefixed with @, and an element's text becomes #text when the element also has attributes or children. An element with nothing but text simply becomes that text, which is what keeps the output readable.
- Does it convert types?
- Not by default, because XML is untyped — every value in it is text, and deciding that '007' is a number is a guess. Turn on type detection and it applies the same round-trip rule used by the CSV converter: text becomes a number only if writing that number back gives the same characters.