A JSON serializer for Python
Project description
# Objackson
This is a JSON serializer for Python that supports deep serialization of objects and full reconstruction of object structure on deserialization.
At the moment it does not support circular references.
# How to use
from objackson import obj2json, json2obj
class MyClass:
def __init__(self, x=0, y=0):
self.__x = x
self.__y = y
@property
def x(self):
return self.__x
@property
def y(self):
return self.__y
def __eq__(self, obj)
return self.x == obj.x and self.y = obj.y
def main():
obj1 = TestClass(2, 3)
json = obj2json(obj1)
obj2 = json2obj(json)
# obj2 is a copy of obj1. Test it:
if obj1 == obj2:
print("SUCCESS")
else:
print("FAIL")
if __name__ == "__main__"
main()
For a class to be serializable, it must have a constructor that allows 0-arguments initialization.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Objackson-1.0.0.tar.gz
(7.4 kB
view hashes)
Built Distribution
Close
Hashes for Objackson-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78c844ef7b2475a08dbe875bc97e4b9c09859540432048c673c09e784bc7558f |
|
MD5 | 96074562021ef62dde2aa491ff021eda |
|
BLAKE2b-256 | 2d391a0bf39076b61811aac00dbd90ab76daa50600200a8cd7af45bb8c2ebd80 |