XML to JSON Converter
XML is alive and well in legacy systems, configuration files, financial feeds (XBRL, ISO 20022), RSS, SOAP responses, and Office Open XML documents under the hood. JSON is the format every modern tool actually wants. Converting between them is straightforward in concept and full of small decisions in practice: do attributes get a prefix? Do repeating elements become arrays automatically? How is mixed content handled? This tool exposes those decisions as options and runs the conversion entirely in your browser.
How XML Maps to JSON
Elements become object properties. An element with only text content becomes a string value: <name>Derek</name> → "name": "Derek". An element with attributes and text gets both, with attributes prefixed (@_ by default) and the text under a #text key: <link href="x">Click</link> → { "@_href": "x", "#text": "Click" }. An element with nested children becomes a nested object. Multiple elements with the same name at the same level become an array of objects — this is configurable, since not every repeated element should always be an array.
Attribute Prefixes and Text Keys
Without a prefix, XML attributes would collide with element child keys (an element named id nested inside one with an id attribute would lose data). The default prefix @_ follows the fast-xml-parser convention. Switch to no-prefix mode if your schema guarantees no collisions and you want cleaner output, or to any custom prefix (@, $, _) that matches downstream expectations. The text-content key for elements with both attributes and text is #text by default, also configurable.
Array Handling for Repeating Elements
By default, fast-xml-parser only creates arrays when it sees the same element name more than once at the same level. A list of one item stays as a single object, which causes problems downstream when consumers expect an array. The always-array option forces specified element names to always be arrays, even when there is only one occurrence. Common case: an RSS feed with one item should still emit items as an array of one, so the downstream loop is unconditional. The element-name list can be enumerated explicitly or set to a pattern (every element matching a regex).
Edge Cases the Parser Handles
CDATA sections (<![CDATA[...]]>) are unwrapped and their content becomes the element's text value. Namespaces are preserved on element names by default (soap:Envelope stays as the key) and can optionally be stripped. Comments and processing instructions are dropped by default. Self-closing tags become empty objects or null depending on the option. Mixed content (text interleaved with child elements at the same level) is the only case where JSON does not have a clean representation — the parser preserves it as best it can, with a warning, but consumers of mixed-content XML typically need a different tool.
Pair this with related tools: JSON ↔ CSV Converter if the next hop is CSV, YAML ↔ JSON Converter for the YAML side, JSON Formatter to pretty-print or minify the result, and XML Formatter to inspect the source XML first.
Frequently Asked Questions
Built by Derek Giordano · Part of Ultimate Design Tools