title: Organizing JSON files while appending through Python (discord.py) input
body: <p>I'm currently making a bot on Discord.py right now, and one of the commands takes input that would be stored into a JSON file. One of the keys is a sort of ID associated for each object, and its format is basically a sort of alphanumeric code. A sample version of the JSON looks like this:</p>
  <pre><code>{
    &quot;data&quot;: [
      {
        &quot;id&quot;: &quot;tbg210915-1&quot;,
        &quot;date&quot;: &quot;September 15, 2021&quot;,
        &quot;time&quot;: &quot;21:09&quot;,
        &quot;url&quot;: &quot;https://example.com&quot;
      },
      {
        &quot;id&quot;: &quot;tbg210915-2&quot;,
        &quot;date&quot;: &quot;September 15, 2021&quot;,
        &quot;time&quot;: &quot;21:09&quot;,
        &quot;url&quot;: &quot;https://example2.com&quot;
      },
      {
        &quot;id&quot;: &quot;tbg210917-1&quot;,
        &quot;date&quot;: &quot;September 17, 2021&quot;,
        &quot;time&quot;: &quot;01:33&quot;,
        &quot;url&quot;: &quot;https://example3.com&quot;
      },
    ]
  }
  </code></pre>
  <p>What I want to happen is that if I input a new object dict whose id is <code>tbg210916-1</code>, it would be appended between <code>tbg210915-2</code> and <code>tbg210917-1</code>.</p>
  <p>Here is how the command works right now so you know how these are currently being appended:</p>
  <pre><code># function to generate the aforementioned id
  def generateImgID(file, type, img_date):
    # turning input data type into abbreviated codes
    convert_list = {...} # a list of types one can input and what their corresponding code would be
      
    if type in convert_list.keys():
      m = convert_list[type]
  
    # converting Month dd, yyyy format to yymmdd 
    d = datetime.datetime.strptime(img_date, '%B %d, %Y').strftime('%y%m%d')
  
    # that number at the end thingy signifying what nth pic that is in a given day
    new = open(file)
    data = json.load(new)
  
    result = Counter(data.values())[img_date]
    if result == 0:
      num = 1
    else:
      num = result + 1
    
    n = str(num)
  
    return f'{m}{d}-{n}'
  
  # command to add new pic to database of json files
  @client.command()
  async def addpic(ctx):
    def check(message):
      return message.author == ctx.author and message.channel == ctx.channel
  
    ... # here is basically a multi-step input process then for the bot to ask the user what to input
  
  # adding all input to json
    with open(f'image json/{type}.json', 'r') as fp:
      data = json.load(fp)
  
      data[f'{type}'].append({
        &quot;id&quot;: img_id,
        &quot;date&quot;: img_date,
        &quot;time&quot;: img_time,
        &quot;url&quot;: img_url
      })
    
    with open(f'image json/{type}.json', 'w') as fp:
      json.dump(data, fp, indent = 2)
  
    await ctx.send(embed = successembed)
  </code></pre>