Look at jsonpickle.
A quick example and i have removed getter/setter which in not popular or not needed for simple simple attribute access.
For more advance attribute access that return a value can use
A quick example and i have removed getter/setter which in not popular or not needed for simple simple attribute access.
For more advance attribute access that return a value can use
@property
.import jsonpickle class GameEntry: """Represents one entry of a list of high scores.""" def __init__(self, name, score): """Create an entry with given name and score.""" self.name = name self.score = score def __str__(self): """Return string representation of the entry.""" return f'({self.name}, {self.score})' # e.g., '(Bob, 98)' obj = GameEntry('Bob', 98) frozen = jsonpickle.encode(obj) # To disk with open('score.json', 'w') as j_out: print(frozen, file=j_out) # From disk with open('score.json') as j: frozen_obj = jsonpickle.decode(j.read())Test frozen_obj:
>>> frozen_obj.name 'Bob' >>> frozen_obj.score 98 >>> print(frozen_obj) (Bob, 98)