Skip to content
A reusable Django model field for storing ad-hoc JSON data
Branch: master
Clone or download
Pull request Compare This branch is 35 commits ahead of dmkoch:master.
rpkilby Move to CircleCI (#14)
* Fix Django version ranges in tox
* Move from Travis CI to CircleCI
* Combine coverage before reporting
* Replace Travis CI w/ CircleCI badge
Latest commit a533f85 Apr 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
jsonfield
tests
.gitignore Testing updates (#13) Mar 28, 2019
CHANGES.rst Update changelog Dec 21, 2018
LICENSE
MANIFEST.in
README.rst
manage.py
setup.cfg
setup.py
tox.ini Move to CircleCI (#14) Apr 18, 2019

README.rst

jsonfield2

https://circleci.com/gh/rpkilby/jsonfield2.svg?style=shield

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.

Requirements

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

  • Python: 3.4, 3.5, 3.6, 3.7
  • Django: 1.11, 2.0, 2.1, 2.2

Installation

pip install jsonfield2

Usage

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

jsonfield.JSONCharField

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 setup.py
  • Create git tag for version
  • Upload release to PyPI
$ pip install -U pip setuptools wheel
$ rm -rf dist/ build/
$ python setup.py bdist_wheel upload

Changes

Take a look at the changelog.

You can’t perform that action at this time.