title: Remove element from JSON Python
body: <p>I'm trying to make a command for my discord bot that deletes a so called &quot;faction&quot; from a server. The factions are stored in a neat JSON like this</p>
  <pre><code>{
      &quot;Meme Faction&quot;: {
          &quot;members&quot;: [],
          &quot;owner&quot;: 429935667737264139,
          &quot;description&quot;: &quot;This is the description :smile:&quot;,
          &quot;member role&quot;: 773580603072839710,
          &quot;owner role&quot;: 773580603605516290
      },
      &quot;Gamer Faction&quot;: {
          &quot;members&quot;: [],
          &quot;owner&quot;: 429935667737264139,
          &quot;description&quot;: &quot;This is the description :smile:&quot;,
          &quot;member role&quot;: 773580603072839710,
          &quot;owner role&quot;: 773580603605516290
      }
  }
  </code></pre>
  <p>Here's the code that's supposed to remove a faction:</p>
  <pre><code>@commands.command(aliases=[&quot;d&quot;])
  async def delete(self, ctx, *, name: str):
      with open(&quot;configs/factions.json&quot;, &quot;r+&quot;) as f:
          factions_json = json.load(f)
          factions_list = list(factions_json.keys()) # loads JSON keys as list
  
          name_capital = name.title()
          if name_capital in factions_list:
              member_role = ctx.guild.get_role(factions_json[name_capital][&quot;member role&quot;])
              owner_role = ctx.guild.get_role(factions_json[name_capital][&quot;owner role&quot;]) 
  
              await member_role.delete() # deletes faction role
              await owner_role.delete() # deletes faction owner role
  
              # JSON remove code
              factions_json.pop(name_capital) 
              f.seek(0)
              json.dump(factions_json, f, indent=4)
  
              await ctx.message.add_reaction(&quot;✅&quot;)
  </code></pre>
  <p>The issue is, instead of removing the faction from the JSON, it just appends another version of the JSON without the faction to the end. Like this:</p>
  <pre><code>{
      &quot;Meme Faction&quot;: {
          &quot;members&quot;: [],
          &quot;owner&quot;: 429935667737264139,
          &quot;description&quot;: &quot;This is the description :smile:&quot;,
          &quot;member role&quot;: 773580603072839710,
          &quot;owner role&quot;: 773580603605516290
      },
      &quot;Gamer Faction&quot;: {
          &quot;members&quot;: [],
          &quot;owner&quot;: 429935667737264139,
          &quot;description&quot;: &quot;This is the description :smile:&quot;,
          &quot;member role&quot;: 773580603072839710,
          &quot;owner role&quot;: 773580603605516290
      }
  }{
      &quot;Meme Faction&quot;: {
          &quot;members&quot;: [],
          &quot;owner&quot;: 429935667737264139,
          &quot;description&quot;: &quot;This is the description :smile:&quot;,
          &quot;member role&quot;: 773580603072839710,
          &quot;owner role&quot;: 773580603605516290
      },
  }
  </code></pre>
  <p>How can I overwrite the JSON instead of appending to it?</p>