Export Trello board and extract the card names and links using C#

I have a Trello board with tons of cards, most of them archived, and I want to go through all of them and determine which ones are worth documenting. In order to that I need to export the board as JSON and extract out the relevant data for each card – which for me is the title, labels, if it’s archived, and a link to the card. This article shows how to do that.

Export Trello board as JSON

  1. Click Show Menu in the top-right corner
  2. Click …More
  3. Click Print and Export
  4. Click Export as JSON
  5. This will open the JSON in the browser, just wait a lil bit
  6. Right-click and Save As to your computer

Create a new console app project and add Newtonsoft as a reference

I always use Newtonsoft when working with JSON.

Examine the JSON structure

In order to know how to extract the relevant data I first need to examine the data and figure out the structure. Here are the relevant parts of the JSON data:

{ ...irrelevant fields... "cards": [{ ...irrelevant fields... "closed": true, "name": "example card name", "labels": [{"name":"exampleLabel"}], "shortUrl": "the card's url" } }] }

Extract the relevant fields and save as CSV

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace TrelloExtractor { class Program { static void Main(string[] args) { //load the JSON file var jsonFileContent = File.ReadAllText(@"C:\Data\trelloData.json"); //deserialize into a dynamic object using Newtonsoft var json = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(jsonFileContent); //initialize the CSV by writing the header StringBuilder csv = new StringBuilder(); csv.AppendLine("NAME,ARCHIVED,LABELS,LINK"); //extract the relevant fields var cards = json["cards"]; Console.WriteLine($"Loaded {cards.Count} card(s)"); foreach(dynamic card in cards) { var labels = string.Join(" ", (card["labels"] as IEnumerable<dynamic>).Select((label) => label["name"])); csv.AppendLine($"\"{card["name"]}\",{card["closed"]},{labels},{card["shortUrl"]}"); } File.WriteAllText(@"C:\Data\trelloCSV.csv", csv.ToString()); Console.WriteLine("Done"); Console.ReadKey(); } } }

Open in Excel

Now I can use Excel to look at this data.

Leave a Comment