Answers for "how to add json file in python"

4

insert json file in python

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
Posted by: Guest on November-19-2020
0

how to add data to file json in python

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)
Posted by: Guest on December-02-2021

Code answers related to "how to add json file in python"

Python Answers by Framework

Browse Popular Code Answers by Language