json_datetime

Functions

jnrbase.json_datetime.json_serialise(__o)[source]

Custom JSON serialiser.

This simply falls through to default() when there isn’t a custom dispatcher register for a type.

Parameters

__o (Any) – Object to encode

Return type

str

Returns

JSON-encoded string

Implemented with functools.singledispatch().

jnrbase.json_datetime.datetime_serialise(__o: datetime.datetime) → str[source]

Specialisation of json_serialise() for datetime.datetime objects.

jnrbase.json_datetime.timedelta_serialise(__o: datetime.timedelta) → str[source]

Specialisation of json_serialise() for datetime.timedelta objects.

jnrbase.json_datetime.json_using_iso8601(__obj)[source]

Parse ISO-8601 values from JSON databases.

See json.JSONDecoder

Parameters

__obj (Dict) – Object to decode

Return type

Dict

jnrbase.json_datetime.dump()[source]

Simple json.dump() wrapper using json_serialise().

jnrbase.json_datetime.dumps()[source]

Simple json.dumps() wrapper using json_serialise().

jnrbase.json_datetime.load()[source]

Simple json.load() wrapper using json_using_iso8601().

jnrbase.json_datetime.loads()[source]

Simple json.loads() wrapper using json_using_iso8601().

Examples

>>> data = {'test': datetime(2016, 11, 30, 18, 35, tzinfo=timezone.utc)}
>>> dumps(data, indent=None)
'{"test": "2016-11-30T18:35:00Z"}'
>>> loads(dumps(data, indent=None)) == data
True