Free Online XML to JSON Converter

Convert XML data to JSON format instantly. Handles nested elements, attributes, and text content using the browser's built-in XML parser.

How the XML to JSON Converter Works

This tool parses XML input using the browser's built-in DOMParser and recursively converts the XML tree structure into a JSON object. XML elements become JSON object keys, nested elements become nested objects, repeated elements become arrays, and attributes are prefixed with @ symbols.

Conversion Rules

The converter follows these rules: XML elements become JSON keys with their child content as values. If an element contains only text, it becomes a string value. If it contains child elements, it becomes a nested object. Repeated sibling elements with the same name are automatically grouped into arrays. XML attributes are preserved with an @ prefix to distinguish them from child elements.

Limitations and Edge Cases

This is a client-side converter using the browser DOMParser, which handles well-formed XML. XML namespaces are preserved in element names. CDATA sections are treated as text content. Very large XML files may cause performance issues in the browser. For complex XML with mixed content, some information nuances may be simplified in the JSON representation.

Related Tools

Frequently Asked Questions

How are XML attributes handled?
XML attributes are converted to JSON keys prefixed with the @ symbol. For example, becomes {"@id": "1"}. This distinguishes attributes from child elements in the JSON output.
How are repeated elements handled?
When multiple sibling elements share the same name, they are automatically grouped into a JSON array. For example, multiple elements under a parent become an array of item objects.
Does it handle XML namespaces?
Namespace prefixes are preserved in the element names as they appear in the XML. For example, becomes a key named ns:element in the JSON output.
What if my XML is malformed?
The browser DOMParser will report parsing errors for malformed XML. The tool checks for parser errors and alerts you to fix the XML syntax before conversion can proceed.
Can I convert JSON back to XML?
This tool only converts XML to JSON. Converting JSON back to XML requires a separate tool because JSON does not inherently preserve XML-specific features like attributes, processing instructions, or element ordering.