Email2 min read

How to Convert MBOX to JSON for Email Analysis

Turn an MBOX mailbox into a JSON array, one object per email with headers, recipients, bodies and attachment details. Ready for Python, pandas or Node.

By the ZapMorph team

MBOXJSON
On this page
  1. Output shape
  2. How to convert MBOX to JSON with ZapMorph
  3. A quick analysis in Python
  4. More questions your email can answer
  5. Tips
  6. Related
  7. Summary
  8. FAQs

Just want it done?

Open the MBOX to JSON Converter — it runs in your browser and nothing is uploaded.

Open the tool

Want to know who you email most, when you're busiest, or how many newsletters you never read? Your Gmail Takeout has the answers, but MBOX is awkward to parse. JSON drops straight into pandas, a notebook or a quick Node script.

Output shape

[
  {
    "subject": "Your receipt #1042",
    "from": [{ "name": "Stripe", "address": "receipts@stripe.com" }],
    "to": [{ "name": "", "address": "you@gmail.com" }],
    "cc": [],
    "date": "2024-03-18T09:12:00.000Z",
    "text": "Amount paid: $49.00…",
    "html": "<table>…</table>",
    "attachments": [{ "name": "receipt.pdf", "type": "application/pdf", "size": 30720 }]
  }
]

How to convert MBOX to JSON with ZapMorph

1. Open the converter

Go to the MBOX to JSON converter.

MBOX to JSON converter
The MBOX to JSON converter

2. Add your mailbox

Drop in the .mbox file.

MBOX file added
Mailbox ready

3. Convert and download

Click Convert to JSON.

JSON ready to download
One object per email

A quick analysis in Python

import json, collections
emails = json.load(open("Inbox.json"))
senders = collections.Counter(e["from"][0]["address"] for e in emails if e["from"])
print(senders.most_common(10))

That's your top ten senders in four lines.

More questions your email can answer

When are you busiest? (pandas)

import pandas as pd
df = pd.read_json("Inbox.json")
df["date"] = pd.to_datetime(df["date"])
print(df["date"].dt.day_name().value_counts())   # emails per weekday
print(df["date"].dt.hour.value_counts().sort_index())  # emails per hour (UTC)

How many newsletters?

news = [e for e in emails if "unsubscribe" in (e["text"] or "").lower()]
print(len(news), "emails mention unsubscribe")

Biggest attachments:

files = [(a["size"], a["name"], e["subject"]) for e in emails for a in e["attachments"]]
for size, name, subject in sorted(files, reverse=True)[:10]:
    print(f"{size/1e6:.1f} MB  {name}  ({subject})")

Tips

  • Huge Takeout? Use a streaming parser like ijson so you don't load gigabytes into memory.
  • Local AI: feed the text field into a local model or a vector database to search your mail by meaning.
  • Privacy: your mailbox never leaves your device during conversion. Keep the JSON somewhere safe too.

Summary

The MBOX to JSON converter turns a mailbox into structured data that's ready for analysis.

FAQs

What's the shape of the output?

An array of messages, each with subject, from, to, cc, date, text, html and attachments (name, type, size).

Can I load it in Python or JavaScript?

Yes. It's standard JSON: json.load in Python or JSON.parse in JavaScript.

Does it work with Gmail Takeout?

Yes. Takeout exports mail as MBOX.

What format are dates in?

ISO 8601 in UTC, such as 2024-03-18T09:12:00.000Z.

Are attachment files included?

No, only their name, type and size, which keeps the JSON a manageable size.

Is my mailbox uploaded?

No. It's parsed in your browser.

Try the MBOX to JSON Converter

Free to start, no install, and your files never leave your device.

Open the tool

Related guides

All guides