diff --git a/src/database.py b/src/database.py index 3b9de14..0f65e2a 100644 --- a/src/database.py +++ b/src/database.py @@ -1,6 +1,7 @@ import json from src.constants import dbPath +from src.utils import toJson class Database: @@ -10,5 +11,5 @@ class Database: def save(self): f = open(dbPath, 'w') - f.write(json.dumps(self)) + f.write(toJson(self)) f.close() diff --git a/src/utils.py b/src/utils.py new file mode 100644 index 0000000..d98f202 --- /dev/null +++ b/src/utils.py @@ -0,0 +1,5 @@ +import json + + +def toJson(obj): + return json.dumps(obj, default=lambda o: o.__dict__, sort_keys=True, indent=4)