GithubHelp home page GithubHelp logo

django-jsonfield's Introduction

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 support added!

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

http://bradjasper.com

Changes

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

django-jsonfield's People

Contributors

adam-iris avatar admackin avatar bkvirendra avatar bradjasper avatar bruth avatar fletom avatar gaelen avatar jarodl avatar jasonwmiller avatar jrief avatar kr0ntab avatar l0kix2 avatar mwaterfall avatar nicholasserra avatar pelme avatar ross avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.