Skip to main content

An abstract class that supports json serialization/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

Example:
>>> from jsonable import JSONable
>>>
>>>
>>> class Fruit(JSONable):
...     __slots__ = ('type', 'weight')
...
...     def initialize(self, type, weight):
...         self.type   = str(type)
...         self.weight = float(weight)
...
>>> class Pie(JSONable):
...     __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)
True

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

jsonable-0.0.2.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file jsonable-0.0.2.tar.gz.

File metadata

  • Download URL: jsonable-0.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonable-0.0.2.tar.gz
Algorithm Hash digest
SHA256 481845fdd62a8679801eb29ca0332075b9b8c051402623651d20f18638ae3a1a
MD5 d9952023a8a33f6f7a0d1f2a956b9bca
BLAKE2b-256 4972a3b7431c2ffb085b28065e472351d0a216de19d75743bcce94a7d50191e1

See more details on using hashes here.

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