The code below is meant to request nested json datasets from an online database and extract only the information I need. I can print the results, so it basically works. However, I don't know how to write these results on a .csv file. I'm afraid I cannot provide a Minimal Working Example, as this would imply revealing my login and password. However any help on how I could do this would be most welcome, as I am a beginner.
# returns JSON object as a dictionary
json_complete = json.load(f)
# retrieves specific data
for i in json_complete['data']:
# documentId=i['documentId']
if i['topics'] != None:
for x in i['topics']:
documentId=x['documentId']
placeCited=x['topicPlaceName']
year=i['date']['docYear']
month=i['date']['docMonth']
day=i['date']['docDay']
documentDate=str(year)+ "-" + str(month)+"-" + str(day)
print(str(documentId) + ',' + placeCited + ','+ documentDate + ',')
this is a snippet of the output I get:
57217,Iran / Asia / World / Top of the TGN hierarchy,1561-7-26,
57217,Halab / Halab / Suriyah / Asia,1561-7-26,
57224,Istanbul / Istanbul / Marmara / Turkiye,1561-8-8,
57224,Iran / Asia / World / Top of the TGN hierarchy,1561-8-8,
57224,Halab / Halab / Suriyah / Asia,1561-8-8,
I am hoping to get a csv with header along those lines:
'DocumentID', 'Place', 'Date'