XML to JSON converter
Turn an XML file into JSON in your browser. Attributes are kept, and a repeated element is a list every time, so your code reads every record the same way.
Drop an XML file here
An .xml file, or any XML such as RSS, SOAP or a sitemap, up to 100 MB. Its contents stay on your computer.
- No sign-up
- No content uploaded
- Lists that keep their shape
JSON your code can rely on.
Your file stays on your computer
The XML is read and the JSON is written in your browser. Its contents are never sent to Mammoth or anyone else.
Lists keep their shape
If an element repeats anywhere, it is a list everywhere, even in a record where it appears once.
Attributes and text kept
Attributes become @ keys and an element's text goes under #text, so nothing in the file is lost.
How to convert XML to JSON
Each element becomes a key. Text becomes a string, and an element that repeats becomes a list.
- 1
Add your XML
Drop an .xml file on the box, or paste the XML.
- 2
Pick the options
Choose how attributes are written, how lists are made, and whether numbers stay text.
- 3
Download
Save the .json file, or copy the JSON straight into your code.
Other ways to do it
Python's xmltodict library writes the same @ and #text keys. The difference is what happens to lists.
Python with xmltodict
A script that runs every day
- Lists keep the same shapeNo
- Attributes and text keptYes
- Numbers as numbers if you wantNo
- No code to writeNo
- This page
This converter
JSON in one step
- Lists keep the same shapeYes
- Attributes and text keptYes
- Numbers as numbers if you wantYes
- No code to writeYes
How to convert XML to JSON in Python
The xmltodict library reads an XML file into Python, and the json module writes it out. Here is the whole script.
Need a table, not JSON? The XML to Excel converter turns repeated elements into rows. Going the other way? Use the JSON to XML converter.
import json
import xmltodict
with open("orders.xml", "rb") as f:
data = xmltodict.parse(f)
with open("orders.json", "w") as f:
json.dump(data, f, indent=2)One catch: an element that appears once comes out as an object, and as a list when it repeats. Add force_list=("item",) for each element that can repeat.
Your file stays private
The converter runs inside this page. Your XML is read and turned into JSON on your computer, and its contents are never sent to Mammoth. We record only what kind of data it was, such as orders, and its common field names, never a value.
Once the page has loaded, it works with your internet switched off.
Getting the same XML every week?
Mammoth can take it from there. Put each week's XML file in a folder and Mammoth reads the records into one table, ready to filter, join and download as JSON.
Weekly orders
| Week 42 | Oct 13 | Ana Costa | 129.50 | |
| Week 42 | Oct 15 | Ben Ellis | 48.00 | |
| Week 43 | Oct 21 | Chloé Martin | 310.25 | |
| Week 44 | Oct 28 | Dev Patel | 75.90 | |
| Week 44 | Oct 30 | O'Neill & Co | 1,200.00 |
Illustration. Every new file in the folder is added to the same table.