This project provides Zod schemas for validating ChatGPT conversation exports. The goal is to collaboratively build a comprehensive schema for type-safe data handling.
Help us improve the schema by testing it with your ChatGPT export.
- In ChatGPT:
Settings>Data controls>Export data. - Download the
.zipfile from the email and extractconversations.json.
# Install bun (if you haven't already)
curl -fsSL https://bun.sh/install | bash
# Install dependencies
bun install
# Install just (if you haven't already)
# See https://just.systems/man/en/chapter_4.html for installation instructions
# e.g. on macOS:
brew install justAlternatively, if you use Nix and direnv:
direnv allow . # uses flake.nixThe application reads the path to your conversations.json file from the CHATGPT_CONVERSATION_FILE environment variable.
- Place your
conversations.jsonfile in the project (e.g., in the root directory or adata/subdirectory). - Set the
CHATGPT_CONVERSATION_FILEenvironment variable to point to this file. You can do this by creating a.envfile in the project root with the following content:If you useCHATGPT_CONVERSATION_FILE=./path/to/your/conversations.json
direnv, it will automatically load this.envfile (as configured in.envrc). Thesrc/data.tsscript will fall back to./data/chatgpt-export/conversations.jsonif the environment variable is not set.
Execute the tests to validate your data against the schema:
just testIf tests fail:
- Examine the Zod validation errors in the test output (they show the problematic
pathandmessage). - Update the Zod schemas in
src/schema.tsto accommodate your data structure (e.g., add missing fields, mark fields as optional, adjust types). - Re-run
just testuntil all tests pass.
To understand the structure of your export, run the analysis script:
just analysisThis script identifies unique object shapes in your data, which can help in refining or adding new schemas.
Open a Pull Request with your changes to src/schema.ts.
README.md: This file.justfile: Task definitions forjust.flake.nix,.envrc: For Nix and direnv based environment setup.src/:schema.ts: The Zod schema definitions (the main file you'll edit).schema.test.ts: Tests for the schemas.analysis.ts: Script for data structure analysis.data.ts: Loads yourconversations.jsonbased on theCHATGPT_CONVERSATION_FILEenvironment variable.
conversations.json: (You provide this) Your exported ChatGPT data.
Let's build the most accurate Zod schema for ChatGPT exports together!