Skip to content
Free · Runs in your browser

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.

Works with
XMLJSON

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
  • Arla Foods logo
  • Bacardi logo
  • British American Tobacco logo
  • Everest Detection logo
  • Golden Acre logo
  • Handlangers logo
  • Inspired Learning Group logo
  • Kantar logo
  • MUFG logo
  • NielsenIQ logo
  • PTI Digital logo
  • RethinkFirst logo
  • Starbucks logo
  • The Specialist Works logo
What you get

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 it works

How to convert XML to JSON

Each element becomes a key. Text becomes a string, and an element that repeats becomes a list.

  1. 1

    Add your XML

    Drop an .xml file on the box, or paste the XML.

  2. 2

    Pick the options

    Choose how attributes are written, how lists are made, and whether numbers stay text.

  3. 3

    Download

    Save the .json file, or copy the JSON straight into your code.

Your options

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
Other ways

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.

Python with xmltodict
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.

How we handle your data

Once the page has loaded, it works with your internet switched off.

Every month

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.

Try Mammoth free

Weekly orders

Week 42orders-week-42.xml
Week 43orders-week-43.xml
Week 44orders-week-44.xml
DriveDropboxOneDriveSFTP
All ordersUp to date
Oct 13Ana Costa129.50
Oct 15Ben Ellis48.00
Oct 21Chloé Martin310.25
Oct 28Dev Patel75.90
Oct 30O'Neill & Co1,200.00

Illustration. Every new file in the folder is added to the same table.

Questions

XML to JSON questions

Is my XML uploaded anywhere?
No. The page reads the file and writes the JSON inside your browser. Once the page has loaded, it works with your internet switched off.
How are attributes written?
As keys that start with @, such as "@id": "1041". You can pick _ instead, or no prefix at all. When an element has attributes and text, the text goes under "#text".
Why is an element that appears once written as a list?
Because it repeats somewhere else in the file. If one order has two items and another has one, both get a list of items, so your code can loop over every order the same way. Choose Only where repeated if you want a list only where an element appears twice.
Are numbers kept as numbers?
By default every value is text, as it is in the file, so 00123 and 129.50 come out unchanged. Switch on Numbers and true/false as values to get 129.5 and true. A value with a leading zero stays text either way.
What happens to namespaces, CDATA and comments?
Namespace prefixes stay as written, such as "soap:Body", and xmlns declarations are kept as @xmlns keys. CDATA becomes plain text. Comments are left out.
Can I turn the JSON back into XML?
Yes. The JSON to XML converter reads the same @ and #text keys, so a file goes there and back unchanged.
Is there a size limit?
Files up to 100 MB.
Is it free?
Yes, with no account and no email.