I am using Python and I have a JSON file in which I would like to update a value related to a given key. That is, I have the my_file.json
containing the following data
{"a": "1", "b": "2", "c": "3"}
and I would like to just change the value related to the b
key from 2
to 9
so that the updated file look as like:
{"a": "1", "b": "9", "c": "3"}
How can I make that?
I tried the following but without success (the changes are not saved to the file):
with open('my_file.json', 'r+') as f:
json_data = json.load(f)
json_data['b'] = "9"
f.close()