Sort JSON Dictionary by Value

1.1k views Asked by At

How can I organize this JSON file in descending order by value?

{
     "48275928194813456218": 12,
     "57532478653456645734": 26
}
// And sort that into:
{
     "57532478653456645734": 26,
     "48275928194813456218": 12
}

This is what I have so far:

sortedDict = sorted(myDictionary, key=lambda i: int(i), reverse=True)

But this messes with the JSON file and throws errors...can anyone help me figure this out?

1

There are 1 answers

0
WilDev Studios On BEST ANSWER

Found the answer:

I needed to make my code this:

sortedDict = dict(sorted(myDictionary.items(), key=lambda item: item[1], reverse=True))