Skip to main content

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)
  • NamedTuple to dict

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"}'

You can also import dump, load, dumps, and loads directly from json_deserializer which will call json.loads, json.dumps with default=json_deserializer.deserialize.

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

json-deserializer-0.0.7.tar.gz (6.8 kB view hashes)

Uploaded Source

Built Distribution

json_deserializer-0.0.7-py2.py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 2 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