I am trying to read some JSON for a leaderboard for my discord bot, formatted like this:
{"915714438273826858":
[
{"915714438823313420":
["", 0]
},
[
{"747797252105306212":
[1, 2]
},
{"695390884291674153":
[3, 8]
}
]
]
}
I can read the first part fine, but reading this list here is giving me some problems:
[
{"747797252105306212":
[1, 2]
},
{"695390884291674153":
[3, 8]
}
]
How can I read the values of each of the dictionaries in the list? For example, say I want to get the dictionary with the key "747797252105306212"'s sub-list, so I could get [1,2]?
Currently, my method is to get all the keys in the larger list using
all_keys = set().union(*(d.keys() for d in lb))
all_keys = list(all_keys)
and then using the order in all_keys to call the dictionary. For example, sometimes, all_keys shows ["747797252105306212","695390884291674153"], and I can call the dictionaries using the above order, as "747797252105306212"'s index is 0 in both all_keys and in the JSON list. However, sometimes all_keys is out of order, making the program call the wrong dictionary, causing this method to be obsolete. Is there any way to fix this, or a different method?