I am trying save the Dictionary type of my data to the json file of txt file using python3.
Example the form of my data like this:
listdic = []
dic1 = {"id": 11106, "text": "*Kỹ_năng đàm_phán* , thuyết_phục"}
dic2 = {"id": 11104, "text": "*Ngoại_hình ưa_nhìn* , nhanh_nhẹn , giao_tiếp tốt"}
dic3 = {"id": 10263, "text": "giao_tiếp tốt"}
listdic.append(dic1)
listdic.append(dic2)
listdic.append(dic3)
And i want it be saved to my json file like this:
i readed some solution on internet and i tried:
f = open("job_benefits.json", "a", encoding= 'utf-8')
for i in listdic:
i = json.dumps(i)
f.write(i + '\n')
f.close()
but the result i have is like this:
and then i try to read file and this is my the result:
f = open("job_benefits.json", "r", encoding= 'utf-8')
listdic = f.readlines()
for i in listdic:
print(i)
That not the way write and read the data to json file i want and some body can help to solve this case ??
Thank you very muck and sorry about my grammar !