Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Extensible default function for JSONEncoder

Project description

Overview

Whilst looking about to see if anyone had proposed a __json__ protocol for Python, I found this article and it struck me as so simple and obviously right.

So, I decided to provide a lib to make it easier for everyone.

Usage

Just pass json_default.default as the default function when calling json.dump(s).

import json

from json_default import default

...

return json.dumps(mydata, default=default)

If you have more types you want to define serialisation for, just add them:

from json_default import default


@default.register(mytype):
def _(obj):
    ...

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 json-default, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size json_default-0.2-py2.py3-none-any.whl (3.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size json_default-0.2.tar.gz (2.7 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