XML to JSON Converter
Convert XML documents to JSON format instantly in your browser. Handles nested elements, repeated child tags (converted to arrays), and custom indent styles.
{
"person": {
"name": "Alice",
"age": 30
}
} How It Works
Formula
DOMParser → recursive node traversal → JSON.stringify Worked Example
<person><name>Alice</name><age>30</age></person> converts to {"person":{"name":"Alice","age":30}}
XML to JSON Conversion Rules
This converter applies the following standard rules when translating XML to JSON:
| XML Feature | JSON Representation |
|---|---|
| Element with text | "tagName": "textValue" |
| Nested element | "tagName": { ... } |
| Repeated same-name elements | "tagName": [ ... ] (array) |
Empty element <tag/> | "tagName": null |
| Numeric text content | JSON number (e.g., 30) |
| Boolean text content | JSON boolean (true / false) |
The root XML element becomes the top-level key in the output JSON object. The entire output is valid, standards-compliant JSON ready for consumption by any programming language.
Frequently Asked Questions
How are repeated XML elements handled?
When the same tag name appears more than once under a parent element, all instances are grouped into a JSON array. For example, multiple <item> tags become an array under the 'item' key.
What happens to XML attributes?
This converter focuses on element content and child elements. XML attributes are not currently included in the JSON output. Use the element-based approach for maximum compatibility.
Are numeric and boolean values detected?
Yes. Text content that parses as a valid number (e.g. '30') is converted to a JSON number. 'true' and 'false' text content is converted to JSON booleans.
Is the conversion reversible (XML → JSON → XML)?
Mostly yes for simple structures. Complex XML with attributes, mixed content, or XML namespaces may not round-trip perfectly, as these features have no direct JSON equivalent.
Related Tools
← View all json toolsJson To Excel Calculator
Paste/upload JSON array -> table preview -> download .xlsx/.csv. SheetJS (xlsx) lazy-loaded on click only; flatten nested keys with dot notation. All client-side.
Json Formatter Calculator
Format (indent 2/4/tab), minify, validate; error with line/column; tree view collapse; sort keys option; copy/download.
Json Beautifier
Paste/type JSON -> beautify with 2/4/tab indent, sort keys option, copy & download output. Full client-side validation with error highlighting.
Json To Xml Calculator
Convert JSON to XML. Root element configurable. Pretty-print XML output. Copy & download as .xml.