XML to JSON
This free XML to JSON converter turns XML into JSON entirely in your browser. Paste your markup, upload an .xml file, or drag one in — then read the result and download it. Nothing leaves your device, and there is no sign-up.
There is no single official way to map XML onto JSON. Attributes, namespaces, repeated elements and mixed text can each be mapped several ways, and most converters pick defaults without telling you which. This page states its rules up front and lets you change each one, so the JSON you get is the JSON you expected.
How to use this XML to JSON converter
- Paste XML into the box, upload an
.xmlor.txtfile, or drag a file onto the drop area. - Set the mapping you want: Namespaces, Attributes, Repeated elements, Empty elements, Values and Output.
- Click Convert to JSON (or just wait — it converts as you type), check the result, then Copy JSON or Download .json.
- If the XML is not well-formed, the error names the line and column where parsing stopped.
Conversion rules — exactly what this page does
Attributes
Every attribute becomes a key on its element object, prefixed with @ by default, so <book id="b1"> yields "@id": "b1". Switch to _ for "_id", or to No prefix for a bare "id". Use a prefix: with No prefix, an attribute whose name matches a child element name is overwritten by that element.
Namespaces
- Strip prefixes (default) —
d:bookbecomesbook. The namespace URI is dropped; two elements with the same local name in different namespaces collapse to one key. - Keep prefixes —
d:bookstaysd:book, using the prefix declared in the document. - Full URI keys —
d:bookbecomes{http://example.com/doc}book, which is unambiguous but verbose.
Attribute names follow the same setting. The default namespace (a plain xmlns="…") has no prefix, so its elements are named by local name under all three settings.
Repeated elements — object or array
- Auto (default) — child elements with the same name under the same parent are counted first. Two or more become a JSON array; exactly one becomes a plain value. That means the shape depends on the data: a book with one
<author>gives a string, a book with two gives an array. - Always arrays — every child element is wrapped in an array, so the shape is stable regardless of how many there are. Use this when the JSON feeds code that expects a fixed structure.
Text
- An element that contains only text becomes that text as a value:
<title>Designing Data</title>→"title": "Designing Data". - An element that has text and attributes or child elements (mixed content) puts its text in
#text:<p>Hello <b>world</b></p>→"p": {"b": "world", "#text": "Hello"}. - Whitespace-only text between elements is dropped when Trim whitespace is on. Turn it off to keep indentation exactly as written.
- CDATA sections are treated as text.
Empty elements and values
- An element with no text, no attributes and no children becomes
""by default; switch Empty elements to null fornull. - With Values on Auto, numbers become numbers and
true/falsebecome booleans. Leading-zero strings such as007and digit strings longer than 15 characters stay text, so identifiers are not mangled. Switch to All as text to keep every value verbatim. - The root element is included as the top-level key by default; uncheck Root element to get its contents directly.
What is ignored
Comments, processing instructions and the DOCTYPE are skipped. XML recognises only five built-in entities — &, <, >, ', "; an HTML entity such as is invalid XML and is reported as a parse error with its line and column rather than silently patched.
What this tool supports
- Input — pasted XML, or
.xml/.txtfiles by drag-and-drop or file picker. - Documents — XML 1.0 with namespaces, attributes, nested elements, mixed content, CDATA, comments and processing instructions.
- Encodings — UTF-8 and UTF-16 with a byte-order mark are detected automatically; otherwise the encoding named in the XML declaration is used, including legacy code pages such as GBK, ISO-8859-1 and Windows-1252 when the browser supports them.
- Output — pretty-printed with two spaces, or minified onto one line.
Limits — read this before pasting something huge
- There is no fixed size limit; the ceiling is your device's memory, because the whole document is parsed in your browser. Very large files will slow the page down or fail.
- Above roughly 8 MB of input, or 200,000 elements, the tool warns you that you are in territory where browsers commonly struggle. It still tries — it never silently truncates.
- The XML must be well-formed. Unclosed tags, mismatched names, stray
&characters and undefined entities are reported with line and column. - Internal DTD entity definitions are not expanded; browsers block them for security. Files that depend on custom entities cannot be converted here.
- Extremely deep nesting is limited by the browser's XML parser, not by this page. If it fails, the error is shown rather than a partial result.
Privacy
Uploaded files are read with the browser's own file reader and never leave your device. There is no upload endpoint on this page, no account, and no stored history. You can disconnect from the internet after the page loads and it will still work.
FAQ
Is this XML to JSON converter free?
Yes. It is free with no login and no usage limit, and all processing stays in your browser. For other formats see the JSON to CSV converter, the CSV to JSON converter, the JSON to Excel converter and the CSV to Excel converter.
Do I have to upload my XML file?
No. The file is read locally with the browser's file API and converted in the page. Nothing is uploaded, logged or stored.
How do I convert an XML file to JSON?
Drag the .xml file onto the drop area or pick Upload File and choose it. The converter reads the file, applies the settings you chose, and shows the JSON. Then press Download .json. The downloaded file name carries a timestamp, for example xml-to-json-20260919-234500.json.
Why is one element an object and a similar one an array?
That is the default Auto rule: two or more sibling elements with the same name become an array, a single one does not. If you want a stable shape, set Repeated elements to Always arrays.
How are attributes named in the JSON?
With a @ prefix by default, so id="b1" becomes @id. You can switch to a _ prefix or to no prefix. A prefix avoids collisions with child element names.
What happens to namespaces?
By default prefixes are stripped, so d:book becomes book. Choose Keep prefixes to retain them, or Full URI keys to write the complete namespace URI in the key.
Why does my XML fail with "error on line X"?
The document is not well-formed at that position — commonly an unclosed tag, a mismatched tag name, or an HTML entity like that XML does not define. The message quotes the line and column where the parser stopped so you can jump straight to it.
Can I get minified JSON instead of indented JSON?
Yes. Set Output to Minified for a single-line file, or leave it on Pretty for two-space indentation. Either way you can copy the result or download it.
Is there a file size limit?
No fixed one — the limit is your device's memory. Files above roughly 8 MB or 200,000 elements trigger a warning because browsers commonly struggle there, but the tool still attempts the conversion and reports any failure instead of returning a partial result.
Can I convert JSON back to XML?
Yes — use the JSON to XML converter. It mirrors this page's rules, so the same attribute prefix, the same namespace handling, and text held in #text all come back the other way. For other output shapes, see the JSON to CSV converter or the JSON to Excel converter.