I am making a chess league to track elo and I am storing all the data in json files. However when I use:
json.dumps((objectToSerialize, default=lambda o: o.__dict__,
sort_keys=True, indent=4, separators=(',', ':'))
The object I am trying to serialize:
class Player:
def __init__(self, rating, name):
self.rating = rating
self.name = name
instead of it making a string like this
{
"name": "jack",
"rating": 1500
},
it is like this:
[
"jack",
1500
],
It is important that the values are given identifiers as when I read the data in the program, it cannot be understood.
Is there something I am doing wrong or is there a fix for this?