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
- Example:
>>> 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) True
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
jsonable-0.3.1.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for jsonable-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7754dd27b4734e42e7f8a61c2336bc98082f715e31e29a061a95843b102dc3a |
|
MD5 | cbb3ff7b9db8ad4520d0821b2664388d |
|
BLAKE2b-256 | 0e55c6bcb4ec7f93bf8f98b57d7e185cf5ee02b52473ed84d5611277f710cdcc |