Skip to content

XML to JSON Converter

Parse XML into clean, structured JSON — attributes, arrays, and nested elements handled automatically

0 characters

Convert XML Documents to Structured JSON

XML remains widely used in SOAP APIs, RSS feeds, SVG files, Office documents, and legacy enterprise systems. But modern applications, JavaScript frontends, and REST APIs overwhelmingly use JSON. This converter parses XML using the browser's native DOMParser and builds a clean JSON object that preserves the document's full structure — elements, attributes, text nodes, and CDATA sections — so you can work with the data in any JSON-native environment.

Attributes and Mixed Content

XML elements can carry attributes alongside child elements and text, which has no direct equivalent in JSON. The converter uses a convention widely adopted by libraries like xml2js: attributes go into an"@attributes" object, and text content in mixed-content elements goes into a"#text" property. Elements that contain only text with no attributes are simplified to a plain string value, keeping the output as lean as possible.

Automatic Array Detection

In XML, repeating sibling elements with the same tag name represent a list. The converter detects this pattern and outputs a JSON array instead of overwriting earlier values. A single element stays as an object; two or more siblings with the same name become an array. This matches the behavior most developers expect when consuming XML data programmatically.

CDATA and Special Characters

CDATA sections let XML carry raw text that would otherwise need escaping — embedded HTML, scripts, or markup snippets. The converter extracts CDATA content as plain text and merges it with adjacent text nodes. XML entities like &, <, and > are resolved by the browser's parser, so the JSON output contains the actual characters.

RSS and Atom Feeds

RSS 2.0 and Atom feeds are XML documents with a predictable structure: channels, items, titles, links, and descriptions. Converting a feed to JSON gives you an object you can iterate over in JavaScript, filter by date or keyword, and render in a custom UI — without pulling in an XML parsing library or writing XPath queries.

Privacy

The entire conversion happens in your browser using the native DOMParser API. No data is sent to any server, making this safe for proprietary XML schemas, SOAP responses containing credentials, and any other sensitive data.

$ faq

How are XML attributes converted to JSON?
Attributes are stored under a special"@attributes" key as an object. For example, <item id="5"> becomes {"item": {"@attributes": {"id":"5"}}}. This keeps attributes separate from child elements and text content.
What happens with repeated child elements?
When multiple sibling elements share the same tag name, the converter groups them into a JSON array automatically. For example, three <item> elements inside a <list> produce"list": {"item": [...]}
How is text content handled?
An element that contains only text becomes a simple string value. If an element has both text and child elements or attributes (mixed content), the text is stored under a"#text" key alongside the other properties.
Does the converter handle CDATA sections?
Yes. CDATA content is treated as plain text and merged with any adjacent text nodes. The CDATA wrapper is removed since JSON has no equivalent concept.
Are XML namespaces preserved?
Namespace prefixes in tag names are kept as-is (for example,"soap:Envelope"), so you can still identify namespaced elements in the JSON output. Namespace declarations (xmlns attributes) are included in @attributes.
Can I convert JSON back to XML?
Yes. Txtory also has a JSON to XML converter for the reverse direction. Together, the two tools let you round-trip between formats.
Is my data sent to a server?
No. The conversion runs entirely in client-side JavaScript using the browser's built-in DOMParser. Nothing is uploaded or stored.