Skip to main content
Help us improve Python packaging – donate today!

Enables pretty JSON viewer in Django forms, admin, or templates

Project Description

# django-prettyjson

[![PyPi Version](]( [![Build Status](](

Enables pretty JSON viewer in Django forms, admin, or templates. The viewer is adapted from [jQuery JSONView]( It is compatible with almost anything: JSON stored in a string, a jsonfield (using django.contrib.postgres or [django-jsonfield](, or any python object that can be serialized to JSON (using [standardjson](

## Demo


## Installation

At the command line:

pip install django-prettyjson

## Configuration

Add `'prettyjson'` to `INSTALLED_APPS` in ``:


## Usage

In a form or admin of a model, enable a pretty JSON viewer for a particular field:

from prettyjson import PrettyJSONWidget

class JsonForm(forms.ModelForm):
class Meta:
model = Test
fields = '__all__'
widgets = {
'myjsonfield': PrettyJSONWidget(),

class JsonAdmin(admin.ModelAdmin):
form = JsonForm

Enable pretty JSON viewer for every JSONField of a model:

from django.contrib.postgres.fields import JSONField

class JsonAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {'widget': PrettyJSONWidget }

In templates, you can also enable a pretty JSON viewer. Use the `prettyjson` template tag with a string JSON or with objects (dicts, QuerySets, etc.) that can be serialized to a JSON. Note that the template tag must be loaded using `{% load prettyjson %}`. It also has CSS and JS that must be included using `{% prettyjson_setup %}`.

{% extends "base.html" %}

{% load prettyjson %}

{% block header %}
{{ block.super }}
{% prettyjson_setup %}
{% endblock %}

{% block content %}
{% prettyjson myqueryset %}
{% prettyjson mydict %}
{% prettyjson '{"hey": "guy","anumber": 243,"anobject": {"whoa": "nuts","anarray": [1,2,"thr<h1>ee"], "more":"stuff"},"awesome": true,"bogus": false,"meaning": null, "japanese":"明日がある。", "link": "", "notLink": " is great"}' %}
{% prettyjson '{}' %}
{% endblock %}

The setup includes jQuery, loaded as django.jQuery to avoid namespace conflict. If your page already includes jQuery, use `{% prettyjson_setup jquery=False %}` to avoid loading jQuery a second time.

### Configure Rendering

By default the jsonwidget will render as a raw string with a button to click to change it to parsed json. For it to render as parsed json initially, you can pass an argument:

class JsonAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})}

## Running Tests

In development.

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements-test.txt
(myenv) $ python

## Credits

Dependencies, parts of code, and/or sources of inspiration:

* [jQuery JSONView](
* [standardjson](

Tools used in developing, testing, and/or rendering this package:

* [Cookiecutter](
* [cookiecutter-djangopackage] (


0.1.0 (2016-05-28)

* First release.

0.2.0 (2016-05-29)

* Switched to using standardjson for encoding objects
* Added setup option for those with jquery already loaded

0.2.1 (2016-07-01)

* Fixed manifest

0.2.2 (2016-12-07)

* Added dependencies to

0.3.0 (2017-05-23)

* Added "initial" option to show raw or parsed initial
* Requires six

0.3.1 (2018-04-01)

* Allows CSS control of parsed widget

0.3.2 (2018-04-09)

* Fixes widget media order

0.3.3 (2018-04-13)

* Fixes string passed as parameter

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_prettyjson-0.3.3-py2.py3-none-any.whl (11.1 kB) Copy SHA256 hash SHA256 Wheel 3.6 Apr 13, 2018
django-prettyjson-0.3.3.tar.gz (10.2 kB) Copy SHA256 hash SHA256 Source None Apr 13, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page