Xml to Json
Paste XML or open an .xml file and get clean JSON instantly. Choose how attributes and text are named, whether repeated elements always become arrays, and whether numbers and booleans are converted. The conversion happens entirely in your browser.
Convert XML to JSON
XML ↔ JSON Mapping Reference
A printable reference to XML-to-JSON conventions and a mapping worksheet for planning data migrations.
- Conventions reference (PDF, DOCX)
- Field mapping worksheet (XLSX, PDF)
Formats: PDF, DOCX, XLSX. Instant download after payment (link valid 72 hours, up to 5 downloads). AI-assisted: the templates were drafted with AI help and reviewed and laid out by Kedop.
$3.00 USD, one-time
Secure card checkout by Stripe. Full refund within 7 days — see the refund policy and license.
How XML maps to JSON
XML and JSON describe data differently, so every converter has to make choices. XML has elements, attributes, text content, namespaces and the order of repeated elements; JSON has objects, arrays, strings, numbers, booleans and null. This converter follows the widely used convention in which each element becomes a key, attributes become keys with a prefix, and text inside an element with attributes becomes a “#text” key.
| XML | JSON produced |
|---|---|
<title>Rain</title> | "title": "Rain" |
<book id="b1">…</book> | "book": {"@id": "b1", …} |
<price currency="USD">5.95</price> | "price": {"@currency": "USD", "#text": "5.95"} |
Two or more <book> siblings | "book": [ {…}, {…} ] |
<note/> (empty) | "note": null |
You can change the attribute prefix — some systems expect an underscore or no prefix at all — and the name of the text key.
Arrays: the most common surprise
In XML, a list is just repeated elements, so a single child and a list with one item look identical. By default the converter produces an array only when an element actually repeats. That keeps simple documents tidy, but it means code reading the JSON must handle both a single object and an array. If you are converting many files with the same schema, choose “Always use arrays”: every element becomes an array, which is more verbose but consistent from file to file.
Numbers, booleans and strings
XML text has no types — “44.95”, “true” and “00123” are all just characters. Keeping everything as strings is the safest choice because nothing is lost: leading zeros in ZIP codes or product IDs survive, and very long numbers are not rounded. Choose “Convert numbers & booleans” when you know the data is numeric and want JSON ready for calculations or charting. Only plain decimal numbers are converted; values with leading zeros such as “007” stay as text.
Namespaces
Documents such as RSS/Atom feeds, SOAP messages, SVG and Office files use namespace prefixes like dc:creator or soap:Body. Keeping the prefixes preserves the exact names; stripping them produces shorter keys but can merge two different elements that share a local name, so strip only when you know the document well. Namespace declarations such as xmlns:dc appear as ordinary attributes with the chosen prefix.
Worked example
The sample catalogue above contains two book elements. Each has an id and an available attribute and a price with a currency attribute. With the default options the output is an object whose single key catalog holds a book array of two objects. Switching values to “Convert numbers & booleans” turns "@available": "true" into true and the price text into the number 44.95.
What is not preserved
- Comments and processing instructions such as
<?xml-stylesheet?>are dropped. - Mixed content — text interleaved with child elements, as in
<p>Hello <b>world</b>!</p>— keeps the text joined in one “#text” value, so the exact order is lost. For document-style XML such as XHTML or DocBook, a specialised transformation is a better fit. - Whitespace-only text used for indentation is ignored.
- CDATA sections are included as text.
- DTD entity definitions beyond the standard XML entities are not expanded.
Checking the JSON you get
After converting, spot-check a few records against the original XML: pick an element that appears once and one that repeats, and confirm both are shaped as your code expects. If the JSON will be loaded into a typed language or a database with a fixed schema, the “Always use arrays” and “Keep as strings” options give the most predictable structure, because a field never switches between an object and an array or between a number and a string from one file to the next. When you rename the attribute prefix or text key, make sure the new names cannot collide with real element names in your documents — a document that already has an element called text should not use “text” as the text key.
Privacy and file size
The conversion uses your browser's built-in XML parser; no file is uploaded. Files of several megabytes convert in a moment on a modern computer. Very large files (tens of megabytes) may be slow because the whole document is loaded into memory — for those, a command-line tool or streaming parser is more suitable.
Common uses
Developers use XML-to-JSON conversion to feed legacy SOAP or XML API responses into JavaScript applications, to inspect RSS feeds, to migrate configuration files, and to load data exports from older business systems into document databases or spreadsheets. Copy the output straight into your code, or download it as a .json file.
Frequently asked questions
Is my XML uploaded anywhere?
No. Parsing and conversion run in your browser, and the data never leaves your device.
Why is an element sometimes an object and sometimes an array?
By default only repeated elements become arrays. Choose “Always use arrays” for a consistent structure.
Why is my number in quotes?
Values are kept as strings unless you choose to convert numbers and booleans, which avoids losing leading zeros.
What does the error message mean?
The XML is not well-formed — often an unclosed tag, an unescaped “&”, or two root elements. The message shows where the parser stopped.
Can it convert JSON back to XML?
Not this tool. JSON has no attributes, so reverse conversion needs its own conventions.
How large a file can I convert?
Files of a few megabytes convert almost instantly. The tool accepts files up to 20 MB; beyond that, browser memory becomes the limit and a command-line converter is the better choice.
Does the order of elements survive?
Order is kept within each group of same-named elements, which become arrays in document order. The relative order between different element names is not represented, because JSON objects are unordered by definition.