1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
"""JSON-rendering helpers.
This module provides mixins for the stdlib :class:`json.JSONEncoder` class,
adding serialization methods for other object types, such as
:class:`~datetime.datetime` objects or iterables.
All these are ready to use by using :data:`~jsonext.dumps`.
"""
import functools
import json
from .mixins import (
JSONDateTimeMixin, JSONIterableMixin, JSONToDictMixin, JSONStringifyMixin,
)
from .wrappers import ISO88601Wrapper
class JSONEncoder(JSONDateTimeMixin, JSONIterableMixin, JSONToDictMixin,
JSONStringifyMixin, json.JSONEncoder):
pass
JSONDecoder = ISO88601Wrapper(json.JSONDecoder())
dumps = functools.partial(json.dumps, cls=JSONEncoder)
loads = JSONDecoder.decode
|