I actually try to write JSON in a data.csv file. I tried following solution from stackoverflow: How do I write a Python dictionary to a csv file?
So I come up with these:
with open("data/dataGold.csv", 'w') as f:
w = csv.DictWriter(f, ['data']['user']['repositories']['nodes'], extrasaction='ignore')
w.writeheader()
w.writerow(response)
w.writerow([data['data']['user']['repositories']['nodes']['name'],
data['data']['user']['repositories']['nodes']['forkCount'],
data['data']['user']['repositories']['nodes']['issues']])
My response variable of type 'dict' is:
{'data': {'user': {'name': 'Markus Goldstein',
'repositories': {'nodes': [{'forkCount': 0,
'issues': {'totalCount': 0},
'name': 'repache'},
{'forkCount': 4,
'issues': {'totalCount': 3},
'name': 'nf-hishape'},
{'forkCount': 4,
'issues': {'totalCount': 7},
'name': 'ip-countryside'},
{'forkCount': 42,
'issues': {'totalCount': 29},
'name': 'bonesi'},
{'forkCount': 13,
'issues': {'totalCount': 3},
'name': 'rapidminer-anomalydetection'},
{'forkCount': 0,
'issues': {'totalCount': 0},
'name': 'rapidminer-studio'}]}}}}
There is a TypeError that says no indices allowed. I think that is because I used ['data']['user']['repositories']['nodes'].
The solution I posted the link above works becaus no nested Dict/JSON. So I have no idea how to do in my case with the nested Dict/JSON
So my goal is a CSV that contains name, forkCount and issues as header. And the next lines are the values of the different repo's.
May someone can help me and sorry for my bad english -.- Thank You!