This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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

Project Description

django-jsonfield

django-jsonfield is looking for maintainers that want to help keep the software up-to-date with bug patches & Django versions. Please email bjasper@gmail.com if interested.

django-jsonfield is a reusable Django field that allows you to store validated JSON in your model.

It silently takes care of serialization. To use, simply add the field to one of your models.

Python 3 & Django 1.8 through 1.11 supported!

Use PostgreSQL? 1.0.0 introduced a breaking change to the underlying data type, so if you were using < 1.0.0 please read https://github.com/bradjasper/django-jsonfield/issues/57 before upgrading.

Note: There are a couple of JSONField’s for Django. This one is django-jsonfield here on GitHub but jsonfield on PyPi.

Note: Semver is followed after the 1.0 release.

Install

pip install jsonfield

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

If you need to use your JSON field in an index or other constraint, you can use JSONCharField which subclasses CharField instead of TextField. You’ll also need to specify a max_length parameter if you use this field.

Compatibility

django-jsonfield aims to support the same versions of Django currently maintained by the main Django project. See Django supported versions, currently:

  • Django 1.8 (LTS) with Python 2.7, 3.3, 3.4, or 3.5
  • Django 1.9 with Python 2.7, 3.4, or 3.5
  • Django 1.10 with Python 2.7, 3.4, or 3.5

Testing django-jsonfield Locally

To test against all supported versions of Django:

$ docker-compose build && docker-compose up

Or just one version (for example Django 1.10 on Python 3.5):

$ docker-compose build && docker-compose run tox tox -e py35-1.10

Travis CI

Changes

Take a look at the changelog.

Release History

Release History

This version
History Node

2.0.1

History Node

2.0.0

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.9.23

History Node

0.9.22

History Node

0.9.20

History Node

0.9.19

History Node

0.9.18

History Node

0.9.17

History Node

0.9.15

History Node

0.9.14

History Node

0.9.13

History Node

0.9.12

History Node

0.9.11

History Node

0.9.10

History Node

0.9.9

History Node

0.9.8

History Node

0.9.7

History Node

0.9.6

History Node

0.9.5

History Node

0.9.4

History Node

0.9.2

History Node

0.9

History Node

0.8

History Node

0.7

History Node

0.6

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
jsonfield-2.0.1-py2.py3-none-any.whl (12.3 kB) Copy SHA256 Checksum SHA256 3.6 Wheel Mar 8, 2017
jsonfield-2.0.1.tar.gz (10.2 kB) Copy SHA256 Checksum SHA256 Source Mar 8, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting