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.

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.

Contact

http://bradjasper.com

Changes

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.13.tar.gz (5.9 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for jsonfield-0.9.13.tar.gz
Algorithm Hash digest
SHA256 df2e3d512ea2c3653856ad141914510c4af8132cef0b5bcb6438bdb055147c06
MD5 134b2f96af4a83bccf7e75e86c134cc1
BLAKE2b-256 e8e94b9c6cafa0df7166ba70186b03e9a8c27a2326066b66c59a7bbc35f8ed72

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