Skip to main content

parse_chatgpt_export

Function parse_chatgpt_export 

Source
pub fn parse_chatgpt_export(content: &str) -> Option<Vec<ParsedEvent>>
Expand description

Parse a ChatGPT data-export conversations.json file.

Unlike parse_cc_line/parse_codex_line (one JSONL line in, one event out), a ChatGPT export is a single static JSON array of conversation objects — this function parses the whole file at once and returns every message-bearing event across every conversation it contains.

Returns None when content is not valid JSON or the top level is not a JSON array. The caller treats that as a per-file error so the mirror cursor does not advance: a partially-downloaded export is retried whole on the next tick, never half-consumed. A malformed conversation inside an otherwise-valid array is skipped individually (see parse_conversation) so one bad entry cannot sink the rest of the file.

Each conversation’s mapping forms a tree; events are emitted in deterministic DFS preorder from the root, following each node’s children array order (never JSON object key order). Nodes off the current_node root-to-tip path are flagged is_sidechain, mirroring how Claude Code flags abandoned/regenerated branches.

The returned raw and text fields have secrets masked, exactly like parse_cc_line/parse_codex_line.