Skip to content

Instantly share code, notes, and snippets.

@ricardocabral
Created September 2, 2016 14:38
Show Gist options
  • Save ricardocabral/a8fbdea76dbae646df726686b5589604 to your computer and use it in GitHub Desktop.
Save ricardocabral/a8fbdea76dbae646df726686b5589604 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')
@ricardocabral
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