Skip to main content

How to turn your ChatGPT data export into Markdown files (Python, no packages)

Updated 7 min readMarkdown

Disclosure: this guide comes from SKILLMERC, which makes Threadkeep, a browser add-on named in the last section. Everything before that section uses only ChatGPT and Python.

ChatGPT's own "Export data" gives you every conversation still in your account, but not in a form you can drop into a notes app, a Git repo or a search tool. You get a ZIP with a viewer page and JSON. This guide turns that JSON into one clean Markdown file per conversation with a short Python script that needs no packages.

Step 1: Request the export

On chatgpt.com, by OpenAI's help page on exporting your data:

  1. Open your profile menu and click Settings, then Data controls.
  2. Under Export data, click Export, then Confirm export.
  3. Wait for the email or text with the Download data export link, and open it while signed in to the same ChatGPT account. OpenAI says it can take up to 7 days, and the link expires 24 hours after you get it, so download it the day it arrives.

The export is not available in ChatGPT Business, Enterprise or ChatGPT for Healthcare workspaces.

Unzip it. The files that matter here are conversations.json, or several files named conversations-000.json, conversations-001.json and so on in larger exports. The viewer page, index.html, lets you read and search your chats in a browser. Earlier exports have a chat.html page instead.

Step 2: Understand why the JSON looks strange

OpenAI does not publish a schema for this file, but its shape has been stable enough that many tools rely on it. The file is a list of conversations. Each conversation has a title, a create_time (Unix seconds) and a mapping.

The mapping is a tree, not a list. Every time you edit a prompt or regenerate an answer, ChatGPT keeps the old version as a separate branch. If you read the nodes top to bottom you get abandoned drafts mixed into the chat, which is why naive converters show answers twice.

A trimmed conversation:

{
  "title": "Sort dicts",
  "create_time": 1764000000.5,
  "current_node": "a2",
  "mapping": {
    "u1": {"message": {"author": {"role": "user"},
            "content": {"parts": ["How do I sort a list of dicts by key?"]}},
           "parent": "root", "children": ["a1", "a2"]},
    "a1": {"message": {"author": {"role": "assistant"},
            "content": {"parts": ["(the answer you regenerated)"]}},
           "parent": "u1", "children": []},
    "a2": {"message": {"author": {"role": "assistant"},
            "content": {"parts": ["Use sorted(items, key=lambda d: d['name'])."]}},
           "parent": "u1", "children": []}
  }
}

The trick: current_node points at the last message of the branch you last saw. Start there, follow parent up to the root, then reverse. That gives you the conversation as it looked on screen.

Three more things to skip:

  • System and tool messages. Keep only the user and assistant roles.
  • Hidden messages. Some messages carry "is_visually_hidden_from_conversation": true in their metadata, such as custom instructions sent to the model.
  • Non-text parts. Images and other attachments sit in parts as objects, not strings. Keep the strings.

Step 3: The script

Save this as chatgpt_to_md.py next to your unzipped export folder. It needs Python 3 and nothing else.

import glob, json, re, sys
from datetime import datetime, timezone
from pathlib import Path

src = Path(sys.argv[1] if len(sys.argv) > 1 else ".")
out = Path(sys.argv[2] if len(sys.argv) > 2 else "chats")
out.mkdir(exist_ok=True)

files = sorted(glob.glob(str(src / "conversations*.json"))) if src.is_dir() else [str(src)]
used = set()

def text_of(msg):
    parts = (msg.get("content") or {}).get("parts") or []
    return "\n\n".join(p for p in parts if isinstance(p, str)).strip()

for path in files:
    data = json.loads(Path(path).read_text(encoding="utf-8"))
    for conv in data if isinstance(data, list) else [data]:
        mapping = conv.get("mapping") or {}
        chain, node_id = [], conv.get("current_node")
        while node_id and node_id in mapping:
            chain.append(mapping[node_id])
            node_id = mapping[node_id].get("parent")
        title = conv.get("title") or "Untitled"
        ts = conv.get("create_time")
        day = datetime.fromtimestamp(ts, timezone.utc).strftime("%Y-%m-%d") if ts else "undated"
        lines = [f"# {title}", "", f"Started: {day}", ""]
        for node in reversed(chain):
            msg = node.get("message") or {}
            role = (msg.get("author") or {}).get("role")
            hidden = (msg.get("metadata") or {}).get("is_visually_hidden_from_conversation")
            body = text_of(msg)
            if role in ("user", "assistant") and body and not hidden:
                lines += [f"## {'You' if role == 'user' else 'ChatGPT'}", "", body, ""]
        name = " ".join(re.sub(r'[\\/:*?"<>|]', " ", title).split())[:80] or "Untitled"
        stem, n = f"{day} {name}", 1
        while stem.lower() in used:
            n += 1
            stem = f"{day} {name} ({n})"
        used.add(stem.lower())
        (out / f"{stem}.md").write_text("\n".join(lines), encoding="utf-8")

print(f"Wrote {len(used)} files to {out}/")

Run it on the folder (it picks up every conversations*.json file) or on one file:

python3 chatgpt_to_md.py ./chatgpt-export ./chats

You get one file per conversation, named by start date and title, such as 2025-11-24 Sort dicts.md. Two chats with the same title on the same day get (2) added. Characters that are not allowed in file names become spaces.

Each file looks like this:

# Sort dicts

Started: 2025-11-24

## You

How do I sort a list of dicts by key?

## ChatGPT

Use sorted(items, key=lambda d: d['name']).

Step 4: Check the output

Before you delete the ZIP, open three or four files, including your longest chat:

  • If it says "Wrote 0 files", look in the unzipped folder for more ZIP files and unzip those too. Some exports pack the conversation files one level deeper.
  • If a file has only its title and date, that chat held only pictures, files or tool output. The script keeps text only.
  • If a reply looks cut short, check the chat on chatgpt.com. Content types other than plain text (code runs, web search results, reasoning summaries) can store text outside parts, and this script leaves them out.
  • If your export has no current_node, the format has changed. Print one conversation with json.dumps(data[0], indent=2)[:3000] and adjust the walk.

Step 5: PDF or Word, if you need them

Markdown converts well. With pandoc installed:

pandoc "chats/2025-11-24 Sort dicts.md" -o "Sort dicts.docx"

Open the .docx in Word and use Save As > PDF for a PDF. Pandoc can write PDF directly too, but that needs a LaTeX engine installed.

When the export is the wrong tool

The data export is a backup of everything, and it can take days to arrive. If you want one conversation you have open right now as a file, there are quicker ways: your browser's print window (Ctrl+P or Cmd+P, then "Save to PDF" in Firefox or "Save as PDF" in Chrome), which prints the page with ChatGPT's side bar and buttons around the chat; or copy and paste into a document, which is fine for one answer.

Or an add-on. Threadkeep is a free add-on for Firefox and Chrome that we make. On the chat you have open, it saves Markdown, text or JSON files, or copies the chat to your clipboard, with no limit, and PDF or Word 3 times a day on the free plan (Pro, which is paid, removes that limit). It saves the chat as you see it on screen, keeps code blocks, tables and lists, and reads everything in your browser with no account. It works on ChatGPT, Claude, Gemini and other chat sites. It is made by SKILLMERC and is not made by, endorsed by or affiliated with OpenAI. ChatGPT is a trademark of OpenAI.

Whichever way you choose, the export plus the script above is the one route that gets every conversation out in one go, as plain files you own.

No comments yet. Be the first to comment.