title: How to update a JSON file by using Python?
body: <p>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 <code>my_file.json</code> containing the following data</p>
  
  <pre><code>{"a": "1", "b": "2", "c": "3"}
  </code></pre>
  
  <p>and I would like to just change the value related to the <code>b</code> key from <code>2</code> to <code>9</code> so that the updated file look as like:</p>
  
  <pre><code>{"a": "1", "b": "9", "c": "3"}
  </code></pre>
  
  <p>How can I make that?</p>
  
  <hr>
  
  <p>I tried the following but without success (the changes are not saved to the file):</p>
  
  <pre><code>with open('my_file.json', 'r+') as f:
      json_data = json.load(f)
      json_data['b'] = "9"
      f.close()
  </code></pre>