Giter Club home page Giter Club logo

django-json-field's Introduction

Django JSON Field

django-json-field contains a flexible JSONField and associated form field. The model field is not only capable of serializing common JSON data types (int, float, decimal, string, time, date, datetime, etc.) but also lazily deserializing them so they can be accessed and modified as normal Python objects within Django.

A form field is also provided. It will accept serialized representations:

{"date": "2012-04-23T19:16:54.133", "num": "1.2399"}

And also provides safe access to the datetime module for explicit use:

{"date": datetime.datetime(2012, 4, 23, 19, 16, 54, 133000)}

While the JSON string will not be deserialized until it is accessed it can still be a performance concern, so you may find it valuable to disable the custom deserializer (JSONField(decoder=None)).

django-json-field is also compatible with South and Python 3.

Installation

Install from PyPI:

pip install django-json-field

If installing manually, first install the dependencies:

pip install python-dateutil six

Install from GitHub:

git clone git://github.com/derek-schaefer/django-json-field.git

pip install -e git+git://github.com/derek-schaefer/django-json-field.git#egg=json_field

Configuration

Add json_field to your PYTHONPATH and INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'json_field',
    ...
)

That's all!

Usage

Add a JSONField to your model like any other field.

from json_field import JSONField
from django.db import models

class MyModel(models.Model):

    json = JSONField()

JSONField also has a few additional optional parameters.

  • default: Falls back on "null" if not provided and null=False, otherwise None
  • db_type: Allows you to specify the column type (default: text)
  • lazy: Defer deserialization until the field is directly accessed (default: True)
  • encoder: Custom JSON encoder (default: DjangoJSONEncoder)
  • decoder: Custom JSON decoder (default: json_field.fields.JSONDecoder)
  • encoder_kwargs: Specify all arguments to the encoder (overrides encoder)
  • decoder_kwargs: Specify all arguments to the decoder (overrides decoder)
  • evaluate_formfield: Evaluate (risky) and enable use of the datetime module in the form field (default: False)

License

django-json-field is licensed under the New BSD license.

django-json-field's People

Contributors

derek-schaefer avatar fladi avatar fletom avatar matklad avatar millar avatar somenick avatar

Watchers

 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.