title: Does json.dump() append to file?
body: <p>I'm getting some unexpected behavior with json.dump(). I'm creating a file <code>results</code>(empty), and then using it in the code like this:</p>
  
  <pre><code>        with open(results, 'r+') as fp:
              temp = {}
              try:
                  # file not empty, load existing dict, and add a key value to it
                  temp = json.load(fp)
                  temp[key] = value
              except json.decoder.JSONDecodeError:
                  # file is empty, create a new dict 
                  temp[key] = value
              # write the dictionary back into file
              json.dump(temp, fp)
  </code></pre>
  
  <p>If the above quote executes once, it works fine. However, if I execute it twice, I'm expecting to have a single dictionary with two keys: <code>{key1: value1, key2: value2}</code>, but I get instead two dictionaries: <code>{key1: value1}{key2: value2}</code>. What could be the reason for such behavior?</p>