# django-jsonfield /

Filename Size Date modified Message
jsonfield
128 B
419 B
66 B
2.4 KB
717 B
1.4 KB

# django-jsonfield

I had a serious need for a JSON field for django. There were a couple out there, but none packaged up nicely on bitbucket/github that were usable with pip install -e.

So I took the code from David Cramer's blog, and packaged it up.

## Usage

To use, just install the package, and then use the field:

from django.db import models
import jsonfield

class MyModel(models.Model):
the_json = jsonfield.JSONField()


Now, it will validate the JSON on entry, and store it as a string in the database. When you instantiate/fetch the object, it will be turned back into a python list/dict/string.

There are also a couple of other bits and bobs:

## Extras

### jsonify templatetag

This allows you to convert a python data structure into JSON within a template:

{% load jsonify %}

<script>
var foo = {{ bar|jsonify }};
</script>


## History

### 0.8.7

Better handle null=True and blank=True: it should make sense what they do now.

### 0.8.5

Allow for '{}' and '[]', and make them not appear to be None.

### 0.8.4

Ensure the version number file is installed with the package.

### 0.8.3

Store the version number in one place only, now.

### 0.8.1

Converting to string does nothing, as serializing a model instance with a JSONField would have a string version of that field, instead of it embedded inline. (Back to pre 0.8 behaviour).

Added better querying support: (field__contains={'key':'value','key2':'value2'} works.)

Removed JSONTableWidget from package.

### 0.8

(Many thanks to IanLewis for these features)

Supports django 1.2

Supports callable and json serializable objects as default

Implemented get_db_prep_value()