XML to JSON Converter

Convert between XML and JSON formats instantly. Properly handles attributes, text nodes, CDATA sections, comments, and namespaces. 100% client-side — no data leaves your browser.

XML → JSON
JSON → XML

About XML to JSON Conversion

XML (Extensible Markup Language) and JSON (JavaScript Object Notation) are the two dominant data interchange formats used across the software industry. While XML has been the backbone of enterprise systems, SOAP web services, and configuration files for decades, JSON has become the preferred format for REST APIs, modern web applications, and NoSQL databases. Converting between these formats is a daily task for developers working with diverse systems.

Why Convert XML to JSON?

Modern web applications and mobile apps overwhelmingly use JSON for data exchange because of its lightweight syntax, native JavaScript support, and simpler parsing. When integrating with legacy systems, enterprise services, or government APIs that still use XML, converting to JSON simplifies frontend consumption. JSON objects map directly to JavaScript objects, Python dictionaries, and similar structures in every modern language, while XML requires dedicated DOM or SAX parsers.

Handling XML Attributes

One of the key challenges in XML-to-JSON conversion is representing XML attributes. XML elements can have both attributes and child elements, a concept that has no direct equivalent in JSON. This converter uses the widely adopted convention of prefixing attribute names with @ in the JSON output. For example, <item id="1"> becomes {"item": {"@id": "1"}}. Text content of elements that also have attributes is stored under the #text key.

CDATA Sections

CDATA (Character Data) sections in XML allow embedding text that should not be parsed as markup: <![CDATA[This <is> raw text]]>. Our converter preserves CDATA content and extracts it as plain text in the JSON output. This is essential for XML documents that contain HTML fragments, code snippets, or other content with special characters that would otherwise need to be escaped as XML entities.

Namespace Support

XML namespaces prevent element name collisions when combining XML documents from different vocabularies. Namespace prefixes like soap:Envelope or xsi:type are preserved in the JSON output as-is, maintaining the ability to distinguish between elements from different XML schemas. This is particularly important when working with SOAP envelopes, RSS/Atom feeds, SVG graphics, or XSLT transformations that rely on namespaces.

Array Detection

A subtle but important aspect of XML-to-JSON conversion is deciding when child elements should become JSON arrays. When multiple sibling elements share the same tag name, they are automatically grouped into a JSON array. A single element of that name produces a single object. This heuristic works correctly for most XML documents but can produce inconsistent results when the same element sometimes appears once and sometimes multiple times. Some converters offer a "force array" option for specific element names to handle this edge case.

JSON to XML Reverse Conversion

Converting JSON back to XML requires conventions for distinguishing between elements and attributes. This tool recognizes keys prefixed with @ as XML attributes and #text as text content. Array values produce repeated sibling elements. Objects become nested elements. Primitive values (strings, numbers, booleans) become text content of their parent element. The output includes a standard XML declaration and is properly indented for readability.

Privacy and Performance

All conversion is performed entirely in your browser using the native DOMParser API for XML parsing and custom JavaScript for the JSON-to-XML direction. No data is sent to any server, making this tool suitable for processing sensitive configuration files, API responses containing customer data, or proprietary XML schemas. The DOMParser provides robust, standards-compliant XML parsing including entity resolution, comment handling, and processing instruction support.