Convert XML Attributes to JSON (@-Prefix Rules)
XML attributes don't have a JSON equivalent, so any XML-to-JSON converter has to invent a convention for them. This one prefixes attribute names with @ and reserves #text for text sitting alongside child elements.
The real behavior
The exact mapping rules: every attribute becomes a @name key (category="fiction" → "@category": "fiction"). If an element has both child elements and its own text, that text is captured as #text — but if the element has only text and no attributes, it collapses to a plain string with no wrapper object at all. Repeated sibling elements with the same tag name (two <book> elements) don't overwrite each other — the second occurrence turns the value into an array automatically.
XML ↔ JSON Converter
Convert between XML and JSON with attribute handling, nested elements, and CDATA support.
XML ↔ JSON Converter: Convert between XML and JSON with attribute handling, nested elements, and CDATA support. Runs entirely in your browser — paste your input, get instant output, nothing is uploaded.
🔒 This tool runs entirely in your browser. No data is sent to any server.