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
----------------
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
Project details
Release history Release notifications | RSS feed
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.8.tar.gz
(5.6 kB
view details)
File details
Details for the file jsonfield-0.9.8.tar.gz
.
File metadata
- Download URL: jsonfield-0.9.8.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e486b17c13c7303d23aff0ee0078ce4cb6fa8b2c02aba4f515357a6abedd72be |
|
MD5 | 9f3aeff736e11a2a36fefd53c0852584 |
|
BLAKE2b-256 | 4537038bbe6347358b67b90f3e10e84dd4764b1f6d9356aae852e4a2535d175a |