Oct-30-2021, 03:30 PM
(Oct-30-2021, 12:16 PM)snippsat Wrote:file_data = json.load(file)When you do thisfile_data
it's a dictionary.
Then on line-11 can not use.append
as that method is only for list.
For dictionary can use.update
Don't usetry: except
with return nothing,when test out stuff want to see all errors.
Quick test working.
import json from pprint import pprint def write_json(new_date, filename='data.json'): with open(filename, 'r+') as file: file_data = json.load(file) #print(file_data) file_data["scripts"].update(new_date) #pprint(file_data) file.seek(0) json.dump(file_data, file, indent=4) if __name__ == '__main__': y = { "emp_name": "Nikhil", "email": "[email protected]", "job_profile": "Full Time", } write_json(y)
I'm getting the same mistake again. Could it be that when we turn it on to read mode, the "data.json" file is empty and gives it this error?
![[Image: jdec33t.png]](https://i.hizliresim.com/jdec33t.png)
![[Image: jdec33t.png]](https://i.hizliresim.com/jdec33t.png)