Skip to content

Instantly share code, notes, and snippets.

@danielres
Last active November 22, 2024 09:41
Show Gist options
  • Save danielres/0e5e322c2b6c5261d4291550fe9ca73d to your computer and use it in GitHub Desktop.
Save danielres/0e5e322c2b6c5261d4291550fe9ca73d to your computer and use it in GitHub Desktop.
Convert all ChatGPPT conversations to csv

ChatGPT conversations.json to csv converter

Bash script to convert all ChatGPT conversations from .json to .csv, for example to import into Notion as a database.

Prerequisites

  • jq

Usage

  1. First export your personal data from ChatGPT (Account Settings > Data Controls > Export Data)
  2. Unzip the downloaded file
  3. There should be a file conversations.json
  4. Execute this bash script in the same directory
  5. This should generate a conversations.csv file
  6. In Notion: import > csv
#!/bin/bash
FILE_OUT=./conversations.csv
# Remove existing file if it exists
rm -f $FILE_OUT
# Add CSV header
echo "title,link,created_at,updated_at,content" >$FILE_OUT
# Append CSV data generated by jq (without repeating the header)
jq -r '
.[] |
{
title: .title,
url: ("https://chatgpt.com/c/" + .id),
create_time: (.create_time | todate),
update_time: (.update_time | todate),
content: (
.mapping
| to_entries
| map(select(.value.message and .value.message.content.parts != null))
| sort_by(.value.message.create_time)
| map(.value.message.content.parts[] | tostring)
| join("\n")
)
} |
[.title, .url, .create_time, .update_time, .content] |
@csv
' ./conversations.json >>$FILE_OUT
rm $FILE_OUT.zip
zip $FILE_OUT.zip $FILE_OUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment