How to Convert Telegram Chat Export JSON into CSV

Published: (February 10, 2026 at 04:27 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Problem

Telegram Desktop allows you to export chats, but the export format is JSON.
When you need to work with a Telegram chat outside of Telegram, the JSON export presents several issues:

  • Messages can be nested and formatted inconsistently.
  • Emojis and multiline messages often break spreadsheets.
  • System messages are mixed with real messages.
  • Large exports can crash Excel entirely.

In practice, this makes Telegram exports hard to use for anything other than storage.

Solution Overview

The high‑level approach is straightforward:

  1. Load the exported result.json.
  2. Iterate through the messages array.
  3. Normalize each message into a flat structure.
  4. Write everything to a properly quoted CSV file.

The tricky part is handling edge cases such as multiline text, emojis, media messages, and system/service messages.

Minimal Example

import json
import csv

with open("result.json", encoding="utf-8") as f:
    data = json.load(f)

with open("chat.csv", "w", newline="", encoding="utf-8") as out:
    writer = csv.writer(out)
    writer.writerow(["date", "sender", "message"])

    for msg in data.get("messages", []):
        date = msg.get("date", "")
        sender = msg.get("from", "Unknown")
        text = msg.get("text", "")

        # If the text field is a list, concatenate its parts
        if isinstance(text, list):
            text = "".join(
                t.get("text", "") if isinstance(t, dict) else t
                for t in text
            )

        writer.writerow([date, sender, text])

This demonstrates the core idea. A production‑ready solution would need to handle many more edge cases, such as:

  • Properly escaping commas and quotes.
  • Preserving emojis and other Unicode characters.
  • Extracting and linking media files.
  • Filtering or labeling system messages.

Further Reading

0 views
Back to Blog

Related posts

Read more »