Convert XML to JSON using the browser DOMParser. Handles XML attributes (prefixed with @), text content (_text), CDATA sections, and namespace stripping. Pretty-print toggle. Paste or upload .xml files.
Paste XML into the input area or drop an .xml file. The tool validates your XML first — parse errors are shown clearly with the line number. Namespaces can be stripped for cleaner output.
Attributes: include as @attr keys or ignore. Text content: _text key or inline. Namespace stripping: remove ns: prefixes. Arrays: force single-child elements to always be arrays (useful for consistent JSON structure).
The JSON output appears with syntax highlighting. Copy to clipboard or download as .json. Use the pretty-print toggle to switch between human-readable and compact formats.
XML attributes become JSON keys prefixed with "@" by convention: <book id="1" author="Smith"> becomes {"book": {"@id": "1", "@author": "Smith"}}. Text content of the element is stored under the "_text" key if attributes are present: <book id="1">War and Peace</book> becomes {"book": {"@id": "1", "_text": "War and Peace"}}. If no attributes exist, text content is the value directly.
When multiple sibling elements have the same tag name, they become a JSON array: <items><item>A</item><item>B</item></items> becomes {"items": {"item": ["A", "B"]}}. If only one item exists, it becomes a single value by default. Enable "Force arrays" to always use arrays even for single elements — this makes code that processes the JSON more consistent and predictable.
CDATA (Character Data) sections in XML contain text that should not be parsed as XML markup: <![CDATA[<b>This is literal text</b>]]>. The browser DOMParser correctly parses CDATA sections and this tool includes their content as plain text in the JSON output, equivalent to regular text content. CDATA is common in RSS feeds and SOAP XML responses.
XML namespaces prefix element and attribute names to avoid collisions: <soap:Body xmlns:soap="http://www.w3.org/2003/05/soap-envelope">. These prefixes (soap:, ns0:, xsd:) clutter JSON keys. Enable namespace stripping to remove the prefix and produce cleaner JSON: soap:Body becomes Body. If your application needs to distinguish namespace-qualified elements, keep namespaces enabled.
The browser DOMParser loads the entire XML document into memory. Files up to 10–20 MB work reliably in most browsers. Very large XML files (100 MB+) may cause browser memory issues. For large XML processing, server-side tools like Python's lxml, Java's SAX parser, or jq with xml2json handle streaming and memory efficiently.
XML is verbose but self-describing and widely used in enterprise systems, SOAP web services, RSS/Atom feeds, SVG, Office documents, and configuration files. JSON is more compact, natively parsed by JavaScript, and preferred for REST APIs. Converting XML to JSON is common when integrating legacy enterprise APIs (which often use SOAP/XML) with modern JavaScript applications.