how can i use python to sort a json by a value for integers?

When I sort by “name” it sorts properly in descending order. But when I sort by value, it doesn’t sort.

value is stored as a string in your data. You need to convert it to a number for sorting properly.

sorted(data["foo"][0]["bar"], key=lambda i: int(i["value"]), reverse=True)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top