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.

XML ↔ JSON: When and Why You Need Both

XML still dominates legacy enterprise integrations — SOAP services, SAML responses, RSS feeds, OOXML documents, and most government APIs. JSON dominates modern web stacks. When the two worlds meet, you need a reliable converter. This tool runs both directions client-side, preserving structure so the round-trip is faithful enough for everyday work.

The mapping problem

XML and JSON are not isomorphic. XML has attributes, namespaces, mixed content, and ordered children — concepts that have no direct JSON equivalent. Most converters fall back to conventions:

  • Attributes become keys prefixed with @ (e.g. @id) or nested under an $ object.
  • Element text content becomes a #text or $ key when the element also has attributes.
  • Repeated child elements become arrays; single elements become objects (which means a single-child case can break consumers expecting an array).
  • Namespaces are dropped or flattened into prefixes — depending on the tool.

Knowing your converter's conventions matters. If you feed the JSON back into a code generator or schema validator, mismatched conventions will produce confusing errors.

Common use cases

Frontend developers convert XML feeds (RSS, Atom, sitemaps) into JSON for SPA consumption. API teams converting from SOAP to REST often start with XML samples and need them as JSON to design the new contract. SecOps engineers parse SAML assertions or STIX/TAXII threat feeds into JSON for ingestion into SIEMs that can't natively read XML. CMS migrations frequently involve converting WordPress WXR exports into JSON for headless re-ingestion.

Pitfalls and edge cases

  • CDATA sections. Most converters preserve the inner text but drop the CDATA marker. Round-tripping won't reproduce the original byte-for-byte.
  • Mixed content. An element containing both text and child elements produces ambiguous JSON; tools differ on how they collapse this.
  • Attribute name collisions. If an attribute and a child element share a name, one will overwrite the other.
  • Self-closing vs empty tag. JSON cannot distinguish <a/> from <a></a>; both become an empty value.

For one-shot conversions during exploration, this tool is fast and private (everything runs in your browser). For pipelines that need byte-perfect round trips, use a typed parser like xml2js with explicit options or move to an XSLT pipeline.

Frequently Asked Questions

How are XML attributes represented in JSON?

Attributes become keys prefixed with @, e.g. becomes {"@id":"42"}.

Can I round-trip XML → JSON → XML and get the original document back?

For most documents, yes — but CDATA markers, namespace prefixes, and self-closing vs empty tag distinctions may not survive.

Does this tool handle namespaces?

Namespace prefixes are kept as part of the element name; the namespace URI itself is not preserved. For namespace-strict use, parse with a typed XML library instead.

Is my data uploaded anywhere?

No. Both XML and JSON stay in your browser — useful when converting SAML assertions or other sensitive payloads.