title: How can I edit/load JSON file in Python
body: <p>I've looked at several questions and I could not get it working! The thing I'm trying to edit JSON file when my bot (discord bot) is being joined to new guild or is leaving guild!</p>
  <p>My default JSON file look like this:</p>
  <pre><code>{
    &quot;guilds&quot;: {
  
    }
  }
  </code></pre>
  <p>What I'm trying to do is add another array where will be listed guild-id and another config for specific servers. I tried this and it did not worked!</p>
  <pre><code>@client.event
  async def on_guild_join(guild):
      with open('data.json') as f:
          data = json.load(f);
  
      data[&quot;guilds&quot;][guild.id] = {
          &quot;join-message&quot;: &quot;Welcome {member} to {server-name}! We hope you enjoy!&quot;
      }
  
      with open('data.json','w') as f:
          json.dump(f,data);
  </code></pre>
  <p>So I want the JSON file looks like this when new guilds are being added:</p>
  <pre><code>{
    &quot;guilds&quot;: {
        {
          &quot;guild-id&quot;: 418718584455,
          &quot;join-message&quot;: &quot;Welcome to blablabla&quot;
        },
    }
  }
  </code></pre>
  <p>and I want this happen always when bot is being joined when bot is leaving I will loop trough list of guilds and find the right and then delete it!</p>
  <p>This seem to be not working, I get no error from it and file isnt being edited!</p>
  <p>If anyone know how could achieve that please reply!</p>