jsabl¶
A thin wrapper of Python stdlib's json module to convert objects to JSON and back, with the purpose of maintaining readability of objects serialized with old versions of their class definition.
Installing¶
> pip install jsabl
Usage¶
Let's make a class JSON-able: we have to
- inherit from
JSONAble
- decorate it with the
@json_info
annotation to declare the associated json "schema" id and version - optionally implement
__from_json_dict__
(class method called during decoding) and/or__to_json_dict__
(instance method called during encoding) if we wish to have control on the process, for example to only dump part of the attributes or perform some custom instance creation. Note that default implementation relies onvars(self)
for dumping and oncls(**dct)
for loading.
TODO complete
See Usage for other possibilities of jsabl
.
Main features / benefits¶
- Add json-ability to any class easily through inheritance without metaclass and without knowledge of internal
JSONEncoder
/JSONDecoder
logic (hooks, etc.). - Write codecs to support several types at a time with
JSONCodec
See Also¶
Others¶
Do you like this library ? You might also like my other python libraries
Want to contribute ?¶
Details on the github page: https://github.com/python-jsabl/jsabl