TypeError: ‘<' not supported between instances of 'dict' and 'dict' leaderboard command error

I’m trying to make a leaderboard command in my bot. It’s supposed to show the top 10 people. I am currently getting this error when I run the command.

TypeError: '<' not supported between instances of 'dict' and 'dict'

My current code for the leaderboard command is:

@bot.command()
async def leaderboard(ctx):
    embed = discord.Embed(title=f"Top 10 {ctx.guild.name} leaderboard:", color=discord.Colour.gold())
    with open('cookiecount.json', 'r') as file:
        data = json.load(file)
    sorted_data = {id: bal for id, bal in sorted(data.items(), reverse=True , key=lambda item: item[1]['cookiecount'])}

    for pos, (id, bal) in enumerate(sorted_data.items()):
        member = ctx.guild.get_member(int(id))
        embed.add_field(name=f"{pos+1} - {member}", value=f"{bal} cookies", inline=False)
        if pos+1 > 9:
            break 
    await ctx.send(embed=embed)

Inside cookiecount.json file:

enter image description here

Answer

If you want to get the data out of the JSON for something specific you have to use the following:

sorted_data = {id: bal for id, bal in sorted(data.items(), reverse=True , key=lambda item: item[1]['cookiecount'])}