Skip to content

Instantly share code, notes, and snippets.

@pvojnisek
Forked from ricardocabral/trello_json_to_xls.py
Created April 8, 2020 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvojnisek/961db832188ef85ce43675221ba5a8f4 to your computer and use it in GitHub Desktop.
Save pvojnisek/961db832188ef85ce43675221ba5a8f4 to your computer and use it in GitHub Desktop.
Convert the JSON file exported by Trello into Excel
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import simplejson, pandas
data = simplejson.loads(open('f877UwgO.json').read())
data2=[]
to_del = ['attachments',
'badges',
'checkItemStates',
'closed',
'desc',
'descData',
'due',
'email',
'id',
'idAttachmentCover',
'idBoard',
'idChecklists',
'idLabels',
'idList',
'idMembers',
'idMembersVoted',
'idShort',
'manualCoverAttachment',
'pos',
'shortLink',
'subscribed',
'url',
]
for card in data['cards']:
for d in to_del:
if d in card: del card[d]
card['labels'] = ';'.join([lb['name'] for lb in card['labels']])
data2.append(card)
df = pandas.DataFrame(data2)
df.to_excel('cards.xlsx')
@pvojnisek
Copy link
Author

Second version

    import simplejson
    import pandas as pd
    json_data = open('f877UwgO.json').read()
    json_data = '['+ json_data + ']'
    data = simplejson.loads(json_data)
    json_data = simplejson.dumps(data[0]['cards'])
    df = pd.read_json(json_data)
    df["labels"] = df["labels"].apply(lambda cell: [row['name'] for row in cell])
    df.drop([u'attachments', u'badges', u'checkItemStates', u'closed', \
           u'desc', u'descData', u'due', u'dueComplete',\
           u'email', u'idAttachmentCover', u'idBoard', u'idChecklists', \
           u'idLabels', u'idList', u'idMembers', u'idMembersVoted', u'idShort'\
           , u'manualCoverAttachment', u'pluginData', u'pos',\
            u'shortLink', u'subscribed', u'url'],inplace=True,axis=1)
    df.to_excel('cards.xlsx')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment