This script converts Claude.ai JSON chat logs into various formats: Markdown, plain text, JSON Lines (JSONL), and PDF.
Output files are named using the sanitized chat title (non-ASCII characters, including emojis, are removed), and chats without a valid title are skipped.
Install the required package:
pip install fpdfRun the script with:
python extract.py [JSON_FILE] [OPTIONS]- JSON_FILE: Path to the input JSON file (defaults to
conversations.jsonin the current directory). - OPTIONS:
-md,--markdown: Convert to Markdown (default).-txt,--text: Convert to plain text.-jsonl,--jsonlines: Convert to JSON Lines (JSONL).-pdf,--pdf: Convert to PDF.
Examples:
-
Convert
conversations.jsonto Markdown:python extract.py -md
or
python extract.py conversations.json -md
-
Convert
my_chats.jsonto plain text:python extract.py my_chats.json -txt
-
Convert
conversations.jsonto JSONL:python extract.py -jsonl
-
Convert
conversations.jsonto PDF:python extract.py -pdf
The script creates output files in the current directory with filenames based solely on the sanitized chat title:
CHAT_TITLE.md(Markdown)CHAT_TITLE.txt(plain text)CHAT_TITLE.jsonl(JSONL)CHAT_TITLE.pdf(PDF)
- Chats with empty or invalid titles are skipped.
- Chat titles are sanitized by removing non-ASCII characters (including emojis) and replacing forbidden characters.
- If no output format is specified, the script defaults to Markdown.
- JSON files are not tracked in this repository and are excluded via the
.gitignorefile. - The script requires the
fpdflibrary for PDF generation.
This script is licensed under the MIT License.