json dump not updating the file

Viewed 18

I wanted to store some value in a json file

json file gets readed but not getting writed

import json 
import os



filepath = os.path.abspath(__file__).replace("test.py", "test.json")
data = json.load(open(filepath, "r"))
out_file = open("test.json", "w")
a = input()
data["cool"] = a
print(data)
json.dump(data,out_file, indent = 6)
out_file.close()
0 Answers
Related