All Projects → rpkilby → Jsonfield

rpkilby / Jsonfield

Licence: mit
A reusable Django model field for storing ad-hoc JSON data

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Jsonfield

Django Admin Json Editor
Adds json-editor for JSONField in Django Administration
Stars: ✭ 118 (-89.28%)
Mutual labels:  json, django
Django Jsoneditor
Django JSONEditor input widget to provide javascript online JSON Editor
Stars: ✭ 124 (-88.74%)
Mutual labels:  json, django
Django Import Export
Django application and library for importing and exporting data with admin integration.
Stars: ✭ 2,265 (+105.72%)
Mutual labels:  json, django
Evalai
☁️ 🚀 📊 📈 Evaluating state of the art in AI
Stars: ✭ 1,087 (-1.27%)
Mutual labels:  django
Awesome Python Primer
自学入门 Python 优质中文资源索引,包含 书籍 / 文档 / 视频,适用于 爬虫 / Web / 数据分析 / 机器学习 方向
Stars: ✭ 57 (-94.82%)
Mutual labels:  django
Django Carrot
A lightweight task queue for Django using RabbitMQ
Stars: ✭ 58 (-94.73%)
Mutual labels:  django
Re Txt
converts text-formats from one to another, it is very useful if you want to re-format a json file to yaml, toml to yaml, csv to yaml, ... etc
Stars: ✭ 59 (-94.64%)
Mutual labels:  json
Django Minicms
Django 开发简易的内容管理系统
Stars: ✭ 56 (-94.91%)
Mutual labels:  django
Http Prompt
An interactive command-line HTTP and API testing client built on top of HTTPie featuring autocomplete, syntax highlighting, and more. https://twitter.com/httpie
Stars: ✭ 8,329 (+656.49%)
Mutual labels:  json
Diver.js
Dives deep into the dom and dumps it in the object literal notation.
Stars: ✭ 57 (-94.82%)
Mutual labels:  json
Dockdj
🚢 A recipe for building 12-factor Python / Django web apps with multi-container Docker and deploying to Amazon AWS using Elastic Beanstalk.
Stars: ✭ 57 (-94.82%)
Mutual labels:  django
Visit nepal
An app to help tourists learn more about Nepal.
Stars: ✭ 57 (-94.82%)
Mutual labels:  django
Rumble
⛈️ Rumble 1.11.0 "Banyan Tree"🌳 for Apache Spark | Run queries on your large-scale, messy JSON-like data (JSON, text, CSV, Parquet, ROOT, AVRO, SVM...) | No install required (just a jar to download) | Declarative Machine Learning and more
Stars: ✭ 58 (-94.73%)
Mutual labels:  json
Feedr
Use feedr to fetch the data from a remote url, respect its caching, and parse its data. Despite its name, it's not just for feed data but also for all data that you can feed into it (including binary data).
Stars: ✭ 56 (-94.91%)
Mutual labels:  json
Django Cms
The easy-to-use and developer-friendly enterprise CMS powered by Django
Stars: ✭ 8,522 (+674.02%)
Mutual labels:  django
Parsrs
CSV, JSON, XML text parsers and generators written in pure POSIX shellscript
Stars: ✭ 56 (-94.91%)
Mutual labels:  json
Gjson
Get JSON values quickly - JSON parser for Go
Stars: ✭ 9,453 (+758.58%)
Mutual labels:  json
Api automation test
接口自动化测试平台,已停止维护,看心情改改
Stars: ✭ 1,092 (-0.82%)
Mutual labels:  django
Django Tsvector Field
Django field for tsvector (PostgreSQL full text search vector) with managed stored procedure and triggers.
Stars: ✭ 56 (-94.91%)
Mutual labels:  django
Unify Jdocs
A new way of working with JSON documents without using model classes or JSON schemas
Stars: ✭ 58 (-94.73%)
Mutual labels:  json

jsonfield

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

jsonfield 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, jsonfield 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.

.. _django.contrib.postgres: https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#jsonfield

Requirements

jsonfield 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

.. _versions of Django: https://www.djangoproject.com/download/#supported-versions

Installation

.. code-block:: python

pip install jsonfield

Usage

.. code-block:: python

from django.db import models
from jsonfield import JSONField

class MyModel(models.Model):
    json = JSONField()

Querying

As stated above, JSONField is not intended to provide extended querying capabilities. That said, you may perform the same basic lookups provided by regular text fields (e.g., exact or regex lookups). Since values are stored as serialized JSON, it is highly recommended that you test your queries to ensure the expected results are returned.

Handling null values

A model field's null argument typically controls whether null values may be stored in its column by setting a not-null constraint. However, because JSONField serializes its values (including nulls), this option instead controls how null values are persisted. If null=True, then nulls are not serialized and are stored as a null value in the database. If null=False, then the null is instead stored in its serialized form.

This in turn affects how null values may be queried. Both fields support exact matching:

.. code-block:: python

MyModel.objects.filter(json=None)

However, if you want to use the isnull lookup, you must set null=True.

.. code-block:: python

class MyModel(models.Model):
    json = JSONField(null=True)

MyModel.objects.filter(json__isnull=True)

Note that as JSONField.null does not prevent nulls from being stored, achieving this must instead be handled with a validator.

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:

.. code-block:: python

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.

.. code-block:: shell

$ pip install tox

Then, run the tox command, which will run all test jobs.

.. code-block:: shell

$ tox

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

.. code-block:: shell

$ 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

.. code-block:: shell

$ 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_.

.. _changelog: https://github.com/rpkilby/jsonfield/blob/master/CHANGES.rst

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].