About this tool
Convert XML to JSON in the exact output convention your parser expects — fast-xml-parser, xml2js, xml-js compact, BadgerFish or plain keys.
There is no single correct JSON representation of XML, which is why fast-xml-parser, xml2js and xml-js all hand you a different object for the same file. This converter parses XML 1.0 once and then emits it in whichever of five documented conventions you choose — fast-xml-parser's @_ prefix and #text, xml2js's $ and _ with explicitArray, xml-js compact's _attributes and _text, the BadgerFish convention's @ and $, or plain keys with no markers at all. It is for developers who need converted output to drop straight into code already written against one of those shapes.
Open XML to JSON Converter on AltFTool — it loads instantly in your browser.
Paste or upload your source content.
Choose the target format or conversion mode.
Copy or download the converted result.
Each preset matches the documented default of its library, so you get the same keys and nesting your code already handles.
Name the tags that must always be arrays and single occurrences stop collapsing into a lone object.
Plain mode flags any attribute whose name clashes with a sibling element, instead of silently merging them.
Match whatever consumes the output. If your Node service already uses xml2js with explicitArray, pick xml2js so every child is an array under $ and _. For a browser app using fast-xml-parser, pick its default with @_ and #text. Choose Plain only when nothing downstream depends on the attribute-versus-element distinction.
A 2007 XML-to-JSON mapping that prefixes every attribute with @ and stores element text under a $ key — so <alice charlie="1">bob</alice> becomes {"alice":{"@charlie":"1","$":"bob"}}. It never collapses an element to a bare string, which makes the shape uniform but verbose.
Because JSON cannot express "a list that happens to have one item" from XML alone — the second occurrence is the first evidence of a list. Add that tag name to the force-array box, or use the xml2js preset, which wraps every child in an array regardless.
In Plain mode, yes: attributes become ordinary keys, so an attribute and a child element with the same name collide, and the tool warns you when that happens. The other four conventions are lossless for elements, attributes and text; comments, processing instructions and the DOCTYPE declaration are dropped in every mode.
Add the XML to JSON Converterwidget to your blog or website — free, responsive, no signup. Just keep the “Widget by AltFTool” credit link visible.
<iframe src="https://www.altftool.com/embed/widget/xml-to-json-converter"
title="XML to JSON Converter — free AltFTool widget"
width="100%" height="640" style="border:0;border-radius:12px;overflow:hidden"
loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<p style="font-size:12px;margin:4px 0 0">Widget by <a href="https://www.altftool.com/tools/all/xml-to-json-converter?utm_source=embed&utm_medium=widget">AltFTool — free online tools</a></p>