Feb-27-2018, 10:07 PM
I have been searching google and working on converting a JSON to a CSV but have not been successful. I call an API from newsapi.org and I can get the json file but when I run the code I get the news1.csv but when I open it, it is blank. I am using Python 2.7.
import json import csv with open('news1.json', 'r') as f: dicts = json.load(f) out = open('news1.csv', 'w') writer = csv.DictWriter(out, dicts[0].keys()) writer.writeheader() writer.writerows(dicts) out.close()