Skip to main content

An abstract class that supports jsonserialization/deserialization.

Project description

This library provides and abstract base class JSONable which enables easy definition of trivially JSON-able python objects.

  • Installation: pip install jsonable
>>> import jsonable
>>> class Fruit(jsonable.Type):
...     __slots__ = ('type', 'weight')
...     def initialize(self, type, weight):
...         self.type   = str(type)
...         self.weight = float(weight)
>>> class Pie(jsonable.Type):
...     __slots__ = ('fruit',)
...     def initialize(self, fruit):
...         self.fruit = [Fruit(f) for f in fruit]
>>> pie = Pie([Fruit('apple', 10.3), Fruit('cherry', 2)])
>>> doc = pie.to_json()
>>> doc
{'fruit': [{'weight': 10.3, 'type': 'apple'}, {'weight': 2.0, 'type': 'cherry'}]}
>>> pie == Pie(doc)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jsonable, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size jsonable-0.3.1-py2.py3-none-any.whl (11.1 kB) File type Wheel Python version 3.4 Upload date Hashes View
Filename, size jsonable-0.3.1.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page