I am trying to write JSON data into the file which is writing in one line as below:
{"AbandonmentDate": "", "Abstract": "", "Name": "ABC"}{"AbandonmentDate": "", "Abstract": "", "Name": "ABC"}
My code is as follow:
with open(file_name, 'w') as file:
for data in results:
saveData = {}
for k,v in data.items():
if v:
saveData[k] = v
else:
saveData[k] = ''
print (json.dumps(saveData))
file.write(json.dumps(saveData, ensure_ascii=False))
file.close()
What I need it as below format:
{"AbandonmentDate": "", "Abstract": "", "Name": "ABC"}
{"AbandonmentDate": "", "Abstract": "", "Name": "ABC"}
I tried several ways from the various answer from StackOverflow, however, I am unable to get it? Is there any way to do it?
file.write('\n')to your loop?,in your json data?with