Paste XML or drop a file. The document is checked for well-formedness first, so a malformed file gets a line and column rather than a silent half-conversion. Everything runs in this tab.
The single-element problem
<items><item/><item/></items> is obviously a list; <items><item/></items> is indistinguishable from a single value.
By default an element becomes an array only when it actually repeats, which produces the most natural-looking JSON. The cost is that your consuming code has to handle both shapes, and it will eventually receive a one-item response and break.
Set Repeated elements to Always arrays and every element becomes an array without exception. The JSON is uglier and the shape is completely predictable. For anything programmatic, choose this one.
Attributes and text content
@, so <person id="1">Ada</person> becomes {"@id": 1, "#text": "Ada"}. The prefix exists because an attribute and a child element can share a name and would otherwise collide silently.
An element with only text and no attributes collapses to the bare value rather than an object with a single #text key, which keeps ordinary documents readable. If you do not need attributes at all, turning them off produces markedly cleaner output.
What does not survive the trip
CDATA sections become ordinary text. Mixed content — text interleaved with child elements, as in <p>Hello <b>world</b>!</p> — loses the ordering, because JSON objects have no way to interleave a string with a key. Document-shaped XML like XHTML converts poorly for that reason; data-shaped XML converts cleanly.Other names for this
Also searched as “xml to json converter”, “convert xml file to json”, “rss to json”.
Questions
- Why do some keys start with @?
- Those are XML attributes. The prefix keeps them from colliding with child elements that happen to share the name. You can turn attributes off entirely in the options.
- A field is sometimes an array and sometimes an object.
- That is the single-element problem. Set “Repeated elements” to “Always arrays” for a shape that never varies.
- What about namespaces?
- Prefixes are kept as part of the key name (
soap:Body), but the namespace URI declarations are not resolved. JSON has no namespace concept to map them onto. - Can it handle an RSS feed or an SVG?
- Yes — both are XML. RSS converts very cleanly. SVG converts correctly but the result is rarely useful, since SVG is document-shaped rather than data-shaped.
- Is my data uploaded anywhere?
- No. The conversion runs as JavaScript inside this tab. Open your browser's Network panel and convert something — you will see no request carrying your data, because there is no server to send it to. You can also turn your Wi-Fi off and convert anyway.