title: How can I fix a key error in a JSON or delete an entry out of it?
body: <p>I have an economy system and in this various things are stored in a JSON.</p>
  <p>There is a <code>wallet</code> and <code>bank</code> amount. I have uploaded the whole thing to Gitlab, so the JSON will not be readable.<br />
  Since I upgraded my bot, which runs with the Red instance, I get a <code>KeyError</code> for 2 users, but also only for a specific query. As an example I have the following command:</p>
  <pre class="lang-py prettyprint-override"><code>    @commands.command()
      async def wallet(self, ctx, user: discord.Member = None):
          &quot;&quot;&quot;Check the wallet amount&quot;&quot;&quot;
          if user is None:
              with open(f'{bundled_data_path(self)}/mainbank.json', 'r') as f:
                  data = json.load(f)
                  user = ctx.author
                  users = await get_bank_data()
                  wallet_amt = users[str(user.id)][&quot;wallet&quot;]
                  await ctx.send(f &quot;**You have {wallet_amt} coins in your wallet.**&quot;)
  </code></pre>
  <p>However, if I now want to query the value of <code>[&quot;bank&quot;]</code> I get a <code>KeyError: ' bank' </code> for the users that were stored in the JSON before the update, this does not apply to <code>wallet</code>. I am still relatively new to a JSON, but is it possible to delete the data from the JSON or add a key by a command?</p>
  <p>Maybe the following definition will also help:</p>
  <pre class="lang-py prettyprint-override"><code>async def open_account(user):
      users = await get_bank_data()
  
      if str(user.id) in users:
          return False
      else:
          users[str(user.id)] = {}
          users[str(user.id)][&quot;wallet&quot;] = 0 # Goes in one command
          users[str(user.id)][&quot;bank&quot;] = 0 # Does not work
  
      with open('data/mainbank.json', 'w') as f:
          json.dump(users, f)
      return True
  </code></pre>
  <p><em><strong>My approaches would be/were:</strong></em></p>
  <ul>
  <li>Try something with <code>.remove(TheUserID)</code> - This is to delete the whole information for the user</li>
  <li><code>del</code> something out of the JSON</li>
  <li>I also read some different posts but I am not sure whether they will work: <a href="https://stackoverflow.com/questions/58228322/how-would-i-delete-something-from-a-json-file">1</a> &amp; <a href="https://stackoverflow.com/questions/45998648/how-to-remove-a-value-from-a-json-array">2</a></li>
  </ul>
  <p>Maybe someone here can tell me if my approaches are the right way to form the whole thing into a command which will for example remove the <code>(user.id)</code> out of the JSON.</p>