0
Q:

add item to json file python

import json
with open('file.json', 'a') as outfile:
    outfile.write(json.dumps(data))
    outfile.write(",")
    outfile.close()
1
a_dictionary = {"d": 4}

with open("sample_file.json", "r+") as file:
    data = json.load(file)
    update(a_dictionary)
    seek(0)
    dump(data, file)
0

New to Communities?

Join the community