XML to JSON converter
Convert XML to JSON: elements become keys, repeated tags become arrays, and attributes are kept with an @ prefix. Parsed by your browser's own XML engine.
Conversion happens in this browser tab. Nothing is uploaded, logged, or stored.
The mapping
The document is parsed with the browser's own XML parser, then walked into a plain JSON structure:
- Each element becomes a key named after its tag.
- Elements with children become objects; elements with only text become scalars.
- Repeated sibling tags collapse into an array.
- Attributes are kept, prefixed with
@, so<user id="7">yields"@id": "7". - An element with both attributes and text puts the text under
#text, because the attributes need somewhere to live alongside it.<user id="7">Ada</user>becomes{"@id": "7", "#text": "Ada"}. - Empty elements become
null. - Numeric and boolean text is converted; everything else stays a string.
The one-element array problem
Telling a one-element list from a single value is the hard part of XML to JSON, and no converter solves it without a schema.
<items>
<item>A</item>
<item>B</item>
</items>
<!-- becomes: { "item": ["A", "B"] } -->
<items>
<item>A</item>
</items>
<!-- becomes: { "item": "A" } — a scalar, not an array -->
The same XML structure produces a different JSON shape depending on how many children
happen to be present. Code that does data.items.item.map(...) works on the
first document and throws on the second.
Defend against it in the consumer, not the converter:
const items = [].concat(data.items?.item ?? []);
What is dropped
| XML feature | Result |
|---|---|
| Comments | Dropped |
| Processing instructions | Dropped |
| Namespace prefixes | Kept as part of the key name, e.g. ns:tag |
| CDATA sections | Unwrapped to their text content |
| Mixed content (text beside elements) | The loose text is lost |
| Element order across different tags | Not preserved as an explicit sequence |
To go back, use JSON to XML. If the result is destined for a config file rather than an API, JSON to YAML is usually the more readable target.
Mixed content is the significant one. Markup like
<p>Hello <b>there</b></p> has no natural JSON
equivalent. For document-shaped XML, JSON is the wrong target format.
Your document stays local
Most XML that needs converting comes from a system somebody would rather not touch — a legacy feed, a bank statement export, a health or insurance interchange file. The formats are old and the contents are usually regulated.
This tool cannot leak them. Parsing uses your browser's own XML engine, the result is assembled in the same tab, and no request carrying your document is ever made.