DEV Community

Dan Dascalescu
Dan Dascalescu

Posted on

How to extract your Facebook Messenger messages from a conversation

If you communicate with people (or bots) over FB messenger, you may find it useful to save a copy of your messages. You can do this by copy/pasting, but the output will be littered with "You sent", scrolling up is a pain, and you can't filter for only what you said.

Fortunately, Facebook provides data exports in JSON format, which we can then filter easily with the jq utility.

Go ahead, Request a Copy in the date range you care about, and select only "Messages":

Facebook 'Download your information' screenshot

Then extract from the archive the file messages/inbox/<your_friend>/message_1.json. Once you have that file, here's how to filter all your messages, sorted chronologically by time:

cat message_1.json | jq -rc 'sort_by(.timestamp_ms) | .[] | select(.sender_name | contains("Dascalescu")) | .content'
Enter fullscreen mode Exit fullscreen mode

(of course, replace "Dascalescu" with your name)

The -r flag unquotes the strings. Useful to unescape "s.

That's it!

Known issues

Characters are output as raw bytes. This will break non-ASCII characters and emojis. Check for solutions on StackOVerflow.

Top comments (0)