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.
Circular references are supported too.
# How to install
Install latest version of Objackson from PyPI:
python3 -m pip install objackson
# 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 zero-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.1.tar.gz
(7.6 kB
view hashes)
Built Distribution
Close
Hashes for Objackson-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec96db4024fa8864aabb60364557be40d4d79637f56c688fad2bd191cc4d6bab |
|
MD5 | 794b3a1322c24978682d00fd99b5f6df |
|
BLAKE2b-256 | 250ce0f9c09b929a3b9df98c9410df797b642b8e47014c009a0bc07ad0531d4c |