Skip to main content

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

Project description

https://circleci.com/gh/rpkilby/jsonfield2.svg?style=shield https://codecov.io/gh/rpkilby/jsonfield2/branch/master/graph/badge.svg https://img.shields.io/pypi/v/jsonfield2.svg https://img.shields.io/pypi/l/jsonfield2.svg

A modern fork of django-jsonfield, compatible with the latest versions of Django.


jsonfield2 is a reusable model field that allows you to store validated JSON, automatically handling serialization to and from the database. To use, add jsonfield.JSONField to one of your models.

Note: django.contrib.postgres now supports PostgreSQL’s jsonb type, which includes extended querying capabilities. If you’re an end user of PostgreSQL and want full-featured JSON support, then it is recommended that you use the built-in JSONField. However, jsonfield2 is still useful when your app needs to be database-agnostic, or when the built-in JSONField’s extended querying is not being leveraged. e.g., a configuration field.

Requirements

jsonfield2 aims to support all current versions of Django, however the explicity tested versions are:

  • Python: 3.6, 3.7, 3.8

  • Django: 2.2, 3.0

Installation

pip install jsonfield2

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

Subclasses models.CharField instead of models.TextField.

Running the tests

The test suite requires tox and tox-venv.

$ pip install tox tox-venv

To test against all supported versions of Django, install and run tox:

$ tox

Or, to test just one version (for example Django 2.0 on Python 3.6):

$ tox -e py36-django20

Release Process

  • Update changelog

  • Update package version in setup.py

  • Check supported versions in setup.py and readme

  • Create git tag for version

  • Upload release to PyPI test server

  • Upload release to official PyPI server

$ pip install -U pip setuptools wheel twine
$ rm -rf dist/ build/
$ python setup.py sdist bdist_wheel
$ twine upload -r test dist/*
$ twine upload dist/*

Changes

Take a look at the changelog.

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

jsonfield2-4.0.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

jsonfield2-4.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file jsonfield2-4.0.0.tar.gz.

File metadata

  • Download URL: jsonfield2-4.0.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for jsonfield2-4.0.0.tar.gz
Algorithm Hash digest
SHA256 7bd43edd85d203ad6edb0ecb39870a1c7a4fadaf7e807b0feeca3da64b086b5d
MD5 9f41c55b8ca8298967eb8349b4cb6beb
BLAKE2b-256 029b4da132909529866d17fcf93432a8832cbb2b05d9ebb6968c535aeb6e2f4d

See more details on using hashes here.

File details

Details for the file jsonfield2-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: jsonfield2-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for jsonfield2-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f19f836c30becbb227ed8c8299da1cfd7f2f7c6ad3ad2a729b59fb75f58ef084
MD5 55fe201c1d8f440fc8040604bcc1cbe0
BLAKE2b-256 c3e22f17efc3bd36d049fc0b8b49442acbdeab5e0f3e4c34a4265f872d92acb7

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