a_dictionary = {"d": 4}
with open("sample_file.json", "r+") as file:
data = json.load(file) # get data from file
update(a_dictionary)
seek(0)
json.dump(data, file) # insert data in file
import json
path="......"
with open(path) as f:
obj = json.load(f)
obj["data"].append({"name":"hayder zaeim"})
with open(path,"w+") as of:
json.dump(obj,of)
import json
def write_json(filename, json_data):
with open(filename) as f:
obj = json.load(f)
obj.append(json_data)
with open(filename,"w+") as of:
json.dump(obj, of)