XML to JSON Converter
Convert XML markup to JSON format
About This Tool
XML feels like reading a foreign language when all your tools speak JSON — you spend more time mentally translating than processing the actual data.
This converter parses XML and emits JSON, handling the tricky bits: attributes versus child elements (attributes become @-prefixed keys), repeated child elements (collected into arrays), text content of mixed elements (placed in a #text key), and namespaces (preserved as prefixes). Comments and processing instructions are dropped by default.
The ambiguity in XML-to-JSON is unavoidable — XML can express structures that JSON can't natively (like attributes), so any conversion makes a choice. The choice here is the BadgerFish-style convention used by many data pipelines, which is reversible and predictable. If you need a different convention (like the one Spring Boot uses), the output is still readable and easy to transform.
The parser walks the XML tree and emits JSON node by node. Each element becomes an object with its attributes prefixed with @ (so they don't collide with child element names), child elements as nested objects or arrays, and inline text as a #text key when the element also has attributes or children. Pure-text elements collapse to just their string value. Repeated child elements (multiple <item> siblings) collect into a JSON array. Self-closing elements become empty objects. Comments and processing instructions drop out unless you toggle them on.
The pain this addresses: someone hands you an XML feed (RSS, Atom, SOAP response, government data export) and your toolchain speaks JSON. You can either spend an afternoon writing a custom parser that handles your specific schema, or convert once and use jq, Lodash, or any standard JSON tool from there. The conversion isn't perfect — some XML structures don't have clean JSON equivalents — but it's good enough that you can get to the data you actually want.
Worked example: an RSS feed with `<item><title>Hello</title><link>https://x.com</link><pubDate>Mon, 01 Jan 2024</pubDate></item>` becomes: ```json {"item": {"title": "Hello", "link": "https://x.com", "pubDate": "Mon, 01 Jan 2024"}} ``` Multiple items wrap in an array automatically. RSS-specific elements like `<media:thumbnail url="x.jpg"/>` become `{"media:thumbnail": {"@url": "x.jpg"}}` — the namespace prefix is preserved verbatim because dropping it would lose information about which spec the field belongs to.
The limitation worth taking seriously: round-tripping. JSON-to-XML is harder than XML-to-JSON because JSON's data model is a strict subset. JSON arrays don't map cleanly to XML structures (XML has no native array — repetition implies it). JSON has no concept of attributes versus elements — both become object keys. Going JSON → XML → JSON usually preserves the data; going XML → JSON → XML often loses information about element ordering, attribute vs element distinctions, or namespace specifics. Treat the JSON output as the canonical form once converted.
The about text and FAQ on this page were drafted with AI assistance and reviewed by a member of the Coherence Daddy team before publishing. See our Content Policy for editorial standards.