xxxxxxxxxx
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)
xxxxxxxxxx
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
xxxxxxxxxx
import json
path="......"
# get data file
with open(path) as f:
obj = json.load(f)
# add data new
obj["data"].update({"name":"M-Sakr"})
# save data new
with open(path,"w+") as of:
json.dump(obj,of)
xxxxxxxxxx
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)