HomeFile Converter ToolsXML to JSON
XML→JS
File

XML to JSON Converter

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.

⚙ Attribute handling📋 Pretty-print🔧 Namespace strip📄 Upload .xml
Converters:
🔒 100% Private — All conversion runs in your browser. No files are uploaded to any server.

📖 How to Use XML to JSON

  1. 1
    Paste or upload XML

    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.

  2. 2
    Set conversion options

    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).

  3. 3
    Copy or download JSON

    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.

💡 Quick Reference

XML feature JSON representation
Attribute id="1" {"@id":"1"}
Text content {"_text":"value"}
Repeated tags ["a","b","c"]
CDATA Plain text content

Frequently Asked Questions — XML to JSON

How are XML attributes represented in JSON?

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.

How are repeated XML elements handled?

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.

What are CDATA sections and how are they handled?

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.

What are XML namespaces and should I strip them?

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.

Can this tool handle large XML files?

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.

What is the difference between XML and JSON for APIs?

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.