Paste XML data or upload a file to get formatted JSON output. Handles nested elements, attributes, and CDATA sections.
Converting XML (Extensible Markup Language) to JSON (JavaScript Object Notation) is a common task for developers integrating APIs, migrating data, or working with modern web services. Here is how to do it with this free online tool:
.xml file from your computer.@attr properties. Enable "Trim whitespace" to clean up extra spaces. Use "Minify JSON" for compact output..json file.The entire conversion runs in your browser using the built-in DOMParser API. Your data is never uploaded to a server or stored anywhere.
Both XML and JSON are popular data interchange formats, but they have different strengths. Here is a quick comparison:
| Feature | XML | JSON |
|---|---|---|
| Syntax | Verbose, tag-based markup | Lightweight, curly braces and brackets |
| Attributes | Supports attributes on elements | No native attribute concept |
| Data types | Everything is text | Strings, numbers, booleans, null, arrays |
| Namespaces | Full namespace support | Not supported |
| Comments | Supported | Not supported |
| File size | Larger due to closing tags | Smaller, more compact |
| Parsing | Requires XML parser (DOM/SAX) | Native JSON.parse() in JavaScript |
| Best for | Document markup, SOAP APIs, config files | REST APIs, web apps, data storage |
Use XML when working with SOAP web services, document-centric data with mixed content, or systems that require schema validation (XSD) and namespaces.
Use JSON when building REST APIs, storing configuration, or exchanging data between web applications. JSON is the default for modern web services and is natively supported by JavaScript.
XML and JSON have fundamentally different data models, so conversion requires some conventions:
Simple elements like <name>Alice</name> become {"name": "Alice"}. If an element has only text content and no attributes, it maps to a plain string value.
Attributes are prefixed with @ to distinguish them from child elements. For example, <user id="1"> becomes {"@id": "1"}. When an element has both attributes and text content, the text is stored under a #text key.
Sibling elements with the same tag name are automatically grouped into JSON arrays. For example, multiple <item> elements become a single "item": [...] array.
Elements with both text and child elements store text under the #text key alongside the child element properties.