I've got the following JSON file named test.json
{"a": ["First letter of alphabet"],"b":["Second letter of alphabet"], "c":["Third letter"]}
I want to add new values to the dictionary in the JSON file
import json
data = json.load(open("test.json","r+"))
data["d"] = [str("fourth letter")]
print(data)
The code above prints the following results to the terminal
{"a": ["First letter of alphabet"],"b":["Second letter of alphabet"], "c":["Third letter"],"d":["fourth letter"]}
But my JSON file remains unchanged
{"a": ["First letter of alphabet"],"b":["Second letter of alphabet"], "c":["Third letter"]}
I want the new values to be stored in the JSON file like this
{"a": ["First letter of alphabet"],"b":["Second letter of alphabet"], "c":["Third letter"],"d":["fourth letter"]}