XML to JSON
Convert XML into structured JSON
Paste XML first to convert it into JSON and inspect the structure immediately; attribute and array mapping rules are available in Advanced mode.
The full guide also includes pitfalls, worked examples, snippets, FAQs, and related tools for checking results or troubleshooting.
About this tool
Map pasted XML to JSON using the browser XML parser. Attributes use @attributes, attributed leaf text uses #text, and repeated sibling names form arrays. Leaf values remain strings. Direct text in mixed-content parents and XML formatting are not preserved, so inspect the result before using it for data migration. Parsing and display happen locally.
Production Snippets
Compare leaf CDATA with mixed parent text
text
Input XML:
<r id="7"><x>1</x><x><![CDATA[2]]></x><p>before <b>bold</b> after</p></r>
Output JSON, compacted here:
{"r":{"@attributes":{"id":"7"},"x":["1","2"],"p":{"b":"bold"}}}
The parent text "before" and "after" is omitted.Failure Clinic (Common Pitfalls)
A valid JSON result is treated as a complete XML archive
Cause: The mapping groups same-named siblings, trims leaf text, and omits mixed parent text, comments, and lexical CDATA boundaries. It does not retain every node’s original order.
Fix: Keep the XML source for archival or round trips. Use this mapping to inspect simple data-oriented XML, then verify the receiving application’s expected field structure.
Frequently Asked Questions
How are attributes, text, and repeated tags mapped?
The root tag is retained. Attributes go under @attributes; a text-only leaf becomes a string, while an attributed leaf uses #text. Repeated sibling tag names become arrays. Numeric-looking values remain strings.
Is all XML content preserved?
No. Text and CDATA inside a leaf become trimmed text. When an element has child elements, its direct mixed text is omitted; comments, CDATA boundaries, and ordering between differently named siblings are not retained. This is not a reversible XML representation.
Does the tool fetch or execute the XML?
It parses pasted text locally with the browser’s XML parser and displays JSON text. It does not send an API request or perform SOAP, DTD, or XSD validation.
Keep browsing