Home

Awesome

WhatsAppChatParser

A C# parser for exported WhatsApp chat histories

Nuget Version Nuget

GitHub last commit GitHub Release Date GitHub

Usage

Parsing

using WhatsAppChatParser;

static void Main(string[] args)
{

    private readonly string filePath = @"C:\..\..WhatsApp Chat with John Doe.txt";

    // Read from file path
    IEnumerable<Message> chats = WhatsAppChat.Parse(filePath);

    // Read from stream
    chats = WhatsAppChat.Parse(new FileStream(filePath, FileMode.Open));

    foreach(var chat in chats)
        Console.WriteLine($"{chat.MessageBy} said {chat.Text} at {chat.TimeStamp}");
}

Data Serialization

WhatsAppChatParser exposes extension methods to serialize the chat list.

To JSON

JSON serialization is handled internally using Newtonsoft.Json. All the JsonConvert.SerializeObject overloads are supported.

using Newtonsoft.Json;
using WhatsAppChatParser;

static void Main(string[] args)
{

    private readonly string filePath = @"C:\..\..WhatsApp Chat with John Doe.txt";
    var chats = WhatsAppChat.Parse(filePath);

    var json = chats.ToJSON(); 
    var indentedJson = chats.ToJSON(Formatting.Indented);
}

To XML

XML serialization is handled internally using System.Xml.Serialization.XmlSerializer.

using WhatsAppChatParser;

static void Main(string[] args)
{

    private readonly string filePath = @"C:\..\..WhatsApp Chat with John Doe.txt";
    var chats = WhatsAppChat.Parse(filePath);

    var xml = chats.ToXML(); 
}

TODO