XML to JSON Converter
Convert XML to JSON online. Paste an XML document and get clean JSON instantly â handles nested elements, attributes, repeated tags, and CDATA, all in your browser.
Features
đˇī¸ Faithful XML Handling
- Nested elements become nested JSON objects
- Repeated sibling tags become JSON arrays
- Attributes captured with an
@prefix - CDATA sections and comments handled correctly
⥠Privacy-First
- Uses your browser's native, spec-compliant XML parser
- No data ever sent to a server
- Clear error messages for malformed XML
- Download or copy the resulting JSON instantly
đ Round-Trip Friendly
- Pairs with our JSON to XML converter
- Ideal for SOAP/legacy API responses
- Great for RSS/Atom feeds and config files
- Toggle attributes off for a cleaner, text-only shape
XML to JSON Guide
XML is still common in enterprise APIs, SOAP services, RSS/Atom feeds, and legacy systems. This converter uses your browser's built-in XML parser (the same one that renders XML documents) so the parsing is fully spec-compliant, then maps elements to JSON objects, repeated tags to arrays, and attributes to @name keys by convention â a widely used approach shared by libraries like xml2js.
Frequently Asked Questions
What happens to XML attributes?
With "Include attributes" checked, each attribute becomes a key prefixed with @ (e.g. id="1" becomes "@id": "1"). If the element also has text content, it's stored under #text. Uncheck the option to discard attributes entirely.
How are repeated elements handled?
When the same tag appears multiple times under one parent, the converter automatically groups them into a JSON array instead of overwriting the key â for example, three <item> tags become an array of three values.
What if my XML is invalid?
The converter reports a parse error with details from the browser's XML parser (unclosed tags, mismatched elements, invalid characters) instead of guessing at a result.
Getting predictable JSON from XML
XML and JSON model data differently. XML has attributes, mixed text and repeated elements, while JSON has only objects, arrays and values. Knowing how these map helps you write code that reads the converted data reliably.
Tips and common pitfalls
- An element that appears once becomes an object property, but the same element repeated becomes an array. If a list can have one item, handle both shapes in your code, or normalize to an array.
- Attributes and text content need distinct keys in JSON. Check how they appear in the output before writing selectors.
- Namespaced names such as
soap:Envelopekeep their prefix, which you may want to strip for readability. - XML values are always text, so numbers and booleans may need converting after parsing.
More questions
Can I convert JSON back to the same XML?
Only approximately. Details such as attribute order, comments and whether a value was an attribute or a child element are not always recoverable. Use our JSON to XML converter and compare the results.
Is it safe to paste XML from an unknown source?
Here, yes: parsing happens in your browser with no external entity loading. In server code, disable DTDs and external entities to avoid XXE attacks.