Skip to main content

Custom datatypes (like datetime) serialization to/from JSON.

Project description

Serialization of Python types to JSON done right.

No more errors like:

TypeError: datetime.datetime(...) is not JSON serializable

In addition to (de-)serialization of basic types (provided by simplejson), jsonplus provides support for exact (de-)serialization of other commonly used types, like: tuple/namedtuple, set/frozenset, complex/decimal.Decimal/fractions.Fraction, and datetime/date/time/timedelta.


jsonplus is available as Python package. To install, simply type:

$ pip install jsonplus


Let’s start with datetime.

>>> from jsonplus import json_loads, json_dumps, json_prettydump

>>> from datetime import datetime
>>> json_dumps({
...     "x": [4,3],
...     "t":
... })

>>> json_loads(_)
{u'x': [4, 3], u't': datetime.datetime(2013, 9, 6, 23, 38, 55, 819791)}

Continue with other datetime.* types, like timedelta, date, and time.

>>> from datetime import timedelta, date, time
>>> print json_prettydump({"dt": timedelta(0, 1234567, 123), "d":, "t":})
    "d": {
        "__class__": "date",
        "__value__": "2013-09-22"
    "dt": {
        "__class__": "timedelta",
        "__value__": {
            "days": 14,
            "microseconds": 123,
            "seconds": 24967
    "t": {
        "__class__": "time",
        "__value__": "23:33:16.335360"

Also, set and complex:

>>> json_dumps([set(range(3)), 1+2j])

>>> json_loads(_)
[set([0, 1, 2]), (1+2j)]

Alternatively, just treat it as a friendly drop-in replacement for json/simplejson.

>>> import jsonplus as json
>>> x = json.loads('{"a":1,"b":2}')
>>> y = json.dumps(x, indent=4)
>>> z = json.pretty(x)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jsonplus, version 0.5.1
Filename, size File type Python version Upload date Hashes
Filename, size jsonplus-0.5.1-py2.py3-none-any.whl (5.6 kB) File type Wheel Python version 3.5 Upload date Hashes View hashes
Filename, size jsonplus-0.5.1.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page