I want to export certain variables to an existing JSON file, but I don't know how to add something to an existing dictionary, I also have dictionaries that already have the variables but I want to update their values, how do I do this?
The python code that I have now makes a new dictionary, which is not what I want, any help is appreciated
Python file:
export_dict = {'salary':salary_int,'interest':interest_int}
with open(f'{os.getcwd()}/Data/Insta-database.json','r') as inputfile:
file = json.load(inputfile)
file['data'].append(export_dict)
with open(f'{os.getcwd()}/Data/Insta-database.json', 'w') as outfile:
json.dump(file, outfile, indent = 4)
JSON file:
{
"data": [
{
"name": "quesa",
"surname": "fum", // I want to add the salary and interest variables beneath these
},
{
"name": "hau",
"surname": "guygo",
"salary": "213,324", // I want to update these values
"interest": "5%", // I want to update these values
},
{
"name": "ksmair",
"surname": "bree",
"salary": "943,229", // I want to update these values
"interest": "15%", // I want to update these values
}
]
}