Skip to main content

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


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)

Uploaded Source

Built Distribution

Objackson-1.0.1-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page