XML to JSON Converter

Convert any XML to JSON with predictable conventions for how attributes, text content, and child elements map. Repeated child elements collect into arrays automatically. Attributes prefix with @, text content becomes #text. Reversible round-trip for the common subset; lossy on mixed content (which JSON can't represent cleanly anyway).

How to use the XML to JSON Converter

Paste XML. The tool walks the DOM and emits a JSON object. Elements with multiple children of the same name collect into arrays; attributes appear as keys with the chosen prefix; element text content uses the chosen text key. Strip namespaces removes the ns: prefix from element / attribute names.

About XML to JSON Converter

XML and JSON model data differently. XML has elements (which can repeat at the same level), attributes (which can't repeat), text content, and mixed content (text and elements interleaved). JSON has only objects, arrays, strings, numbers, booleans, and null. The mapping is straightforward for most cases but requires conventions for the XML-specific concepts: where do attributes go, how do you distinguish a single element from one in an array, what happens to mixed content.

This converter uses the Badgerfish-inspired convention: attributes prefixed with @ sit as siblings of element children, text content goes under #text, multiple children of the same name become an array. The result is unambiguous, round-trips well for non-mixed content, and matches what most XML-to-JSON libraries produce so downstream tooling can consume it.

Common use cases

  • Reading legacy XML APIs from JSON-only code — convert SOAP responses to JSON for easier handling.
  • Config migration — move from XML config (web.xml, log4j.xml) to JSON equivalents.
  • RSS / Atom feed processing — convert feed XML to JSON for use in modern JS apps.
  • One-off scripting — convert XML data so you can query it with jq instead of XPath.

Frequently asked questions

What about mixed content (text + elements interleaved)?

JSON can't cleanly represent mixed content. The converter concatenates text nodes into a single string under the text key; you lose the ordering relative to child elements. For documents heavy on mixed content, XPath is a better tool than JSON.

How are repeated elements handled?

A single occurrence becomes a value; two or more become an array. If you need consistent array shape, post-process the JSON.

Does it handle CDATA?

Yes — CDATA sections are concatenated with regular text content and emitted as plain string.