Skip to main content

A reusable Django field that allows you to store validated JSON in your model.

Project description

A modern fork of django-jsonfield, compatible with the latest versions of Django.

jsonfield2 is a reusable model field that allows you to store validated JSON, automatically handling serialization to and from the database. To use, add jsonfield.JSONField to one of your models.

Note: django.contrib.postgres now supports PostgreSQL’s jsonb type, which includes extended querying capabilities. If you’re an end user of PostgreSQL and want full-featured JSON support, then it is recommended that you use the built-in JSONField. However, jsonfield2 is still useful when your app needs to be database-agnostic, or when the built-in JSONField’s extended querying is not being leveraged. e.g., a configuration field.


jsonfield2 aims to support all current versions of Django, however the explicity tested versions are:

  • Python: 3.4, 3.5, 3.6
  • Django: 1.11, 2.0


pip install jsonfield2


from django.db import models
from jsonfield import JSONField

class MyModel(models.Model):
    json = JSONField()

Advanced Usage

By default python deserializes json into dict objects. This behavior differs from the standard json behavior because python dicts do not have ordered keys. To overcome this limitation and keep the sort order of OrderedDict keys the deserialisation can be adjusted on model initialisation:

import collections

class MyModel(models.Model):
    json = JSONField(load_kwargs={'object_pairs_hook': collections.OrderedDict})

Other Fields


Subclasses models.CharField instead of models.TextField.

Running the tests

The test suite requires tox and tox-venv.

$ pip install tox tox-venv

To test against all supported versions of Django, install and run tox:

$ tox

Or, to test just one version (for example Django 2.0 on Python 3.6):

$ tox -e py36-django20

Release Process

  • Update changelog
  • Update package version in
  • Create git tag for version
  • Upload release to PyPI
$ pip install -U pip setuptools wheel
$ rm -rf dist/ build/
$ python bdist_wheel upload


Take a look at the changelog.

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 jsonfield2, version 3.0.0
Filename, size File type Python version Upload date Hashes
Filename, size jsonfield2-3.0.0-py2.py3-none-any.whl (5.7 kB) File type Wheel Python version 3.6 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page