title: How to append data to a json file?
body: <p>I'm trying to create a function that would add entries to a json file. Eventually, I want a file that looks like </p>
  
  <pre><code>[{"name" = "name1", "url" = "url1"}, {"name" = "name2", "url" = "url2"}]
  </code></pre>
  
  <p>etc. This is what I have:</p>
  
  <pre><code>def add(args):
      with open(DATA_FILENAME, mode='r', encoding='utf-8') as feedsjson:
          feeds = json.load(feedsjson)
      with open(DATA_FILENAME, mode='w', encoding='utf-8') as feedsjson:
          entry = {}
          entry['name'] = args.name
          entry['url'] = args.url
          json.dump(entry, feedsjson)
  </code></pre>
  
  <p>This does create an entry such as <code>{"name"="some name", "url"="some url"}</code>. But, if I use this <code>add</code> function again, with different name and url, the first one gets overwritten. What do I need to do to get a second (third...) entry appended to the first one?</p>
  
  <p><strong>EDIT</strong>: The first answers and comments to this question have pointed out the obvious fact that I am not using <code>feeds</code> in the write block. I don't see how to do that, though. For example, the following apparently will not do:</p>
  
  <pre><code>with open(DATA_FILENAME, mode='a+', encoding='utf-8') as feedsjson:
      feeds = json.load(feedsjson)
      entry = {}
      entry['name'] = args.name
      entry['url'] = args.url
      json.dump(entry, feeds)
  </code></pre>