Skip to main content

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

Project description

django-jsonfield

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.

New: Python 3 & Django 1.7 supported!

PostgreSQL?: Use https://github.com/bradjasper/django-jsonfield/tree/postgresql for now

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 supports Python 2.7-Python 3.3 and Django 1.4+

Why doesn’t it support Python 2.6?

You actually might be OK if you don’t use an OrderedDict, but there are some issues with the simplejson API that make it cumbersome to support.

Why doesn’t it support Django 1.3?

There was a bug that could only be fixed by a feature in Django 1.4. Read More if you’re interested in the details.

Travis CI

https://travis-ci.org/bradjasper/django-jsonfield.png?branch=master

Contact

Web: http://bradjasper.com

Twitter: @bradjasper

Email: contact@bradjasper.com

Changes

v0.9.23, 9/3/2014 – Allowed tests to run in older versions of Django

v0.9.22, 7/10/2014 – Added Django 1.7 support

v0.9.21, 5/26/2014 – Added better support for Python 3 and tests for regex lookups

v0.9.20, 11/14/2013 – Fixed load_kwargs on form fields, added Django 1.6 to automated tests

v0.9.19, 09/18/2013 – Fixed changes to django.six.with_metaclass that broke django-jsonfield for Django 1.6

v0.9.18, 08/23/2013 – Fixed bugs with South datamigration

v0.9.17, 06/07/2013 – Fixed bugs in JSONCharField admin form

v0.9.14/15/16, 04/29/2013 – Python 3 support added!

v0.9.11/12/13, 03/26/2013 – PyPi changes

v0.9.9/10/11, 03/21/2013 – PyPi changes

v0.9.8, 03/21/2013 – Added support for native PostgreSQL JSON data type

v0.9.7, 03/21/2013 – Fix bug #33 where JSONField didn’t correctly store some values inside of strings

Project details


Download files

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

Source Distribution

jsonfield-0.9.23.tar.gz (7.2 kB view details)

Uploaded Source

File details

Details for the file jsonfield-0.9.23.tar.gz.

File metadata

  • Download URL: jsonfield-0.9.23.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonfield-0.9.23.tar.gz
Algorithm Hash digest
SHA256 1707bdfb28fa2465cf5a580330e33d2f3f921d94fab998fab7070a2a0f3266ca
MD5 0a2fe1f58c5165d546675b21dc6022c0
BLAKE2b-256 c628c2417c01f7bf3d3f58f4023158aa752f79c1a330d0a44cf563c0646838cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page