The code below works for updating my json file but it unnecessarily opens the file twice, once to read and then to write. I tried opening it with 'r+' instead of 'r', but then it appended the revised json instead of replacing the original file. 'w+' also didn't work - the file couldn't be read.
Any thoughts or ideas for how to update without opening the file twice?
with open(shared_file_path,'r') as json_file:
data = json.load(json_file)
if data[param] != value:
data[param] = value
with open(shared_file_path,'w') as json_file:
json.dump(data, json_file)