Attempts to correctly deserialize objects that json decoder cannot.
Project description
json-deserializer
Attempts to deserialize objects into a format that json.dumps/json.loads can use.
- Anything that is a Sequence, but not a str will be cast to a list.
- All Mappings will be cast to dicts
- Decimal to floats
- Callable to string (will return Object.repr)
Usage Example
>>> from json import dumps
>>> from collections import UserDict
>>> from json_deserializer import deserialize
>>>
>>> class MyDict(UserDict):
>>> pass
>>>
>>> d = MyDict({"foo": "bar"})
>>> try:
>>> dumps(d)
>>> except Exception as e:
>>> print(e)
Object of type MyDict is not JSON serializable
>>> dumps(d, default=deserialize)
'{"foo": "bar"}'
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
Built Distribution
Close
Hashes for json_deserializer-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84564bfc9ef331ab2543d29beef01ddf3c0de3fe561eebe2400f5224c1f924b9 |
|
MD5 | 828ac01ac60f32b31c5d3a2ae289b71f |
|
BLAKE2b-256 | 728e85f66e70e6b3769213d3f66ad966ebf0a394ecd579c1c9f2cf793c7117c9 |