Skip to main content

django-json-widget

https://badge.fury.io/py/django-json-widget.svg

An alternative widget that makes it easy to edit the new Django’s field JSONField (PostgreSQL specific model fields)

Quickstart

Install django-json-widget:

pip install django-json-widget

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_json_widget',
    ...
)

Add the widget in your admin.py:

from django.contrib import admin
from django.db.models import JSONField
from django_json_widget.widgets import JSONEditorWidget
from .models import YourModel


@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        JSONField: {'widget': JSONEditorWidget},
    }

You can also add the widget in your forms.py:

from django import forms
from django_json_widget.widgets import JSONEditorWidget
from .models import YourModel


class YourForm(forms.ModelForm):
    class Meta:
        model = YourModel

        fields = ('jsonfield',)

        widgets = {
            'jsonfield': JSONEditorWidget
        }

Configuration

You can customize the JSONEditorWidget with the following options:

  • width: Width of the editor as a string with CSS size units (px, em, % etc). Defaults to 90%.

  • height: Height of the editor as a string CSS size units. Defaults to 550px.

  • options: A dict of options accepted by the JSON editor. Options that require functions (eg. onError) are not supported.

  • mode (deprecated): The default editor mode. This argument is redundant because it can be specified as a part of options. Preserved for backwards compatibility with version 0.2.0.

  • attrs: HTML attributes to be applied to the wrapper element. See the Django Widget documentation.

Accessing JsonEditor Instance

The JsonEditor instance is automatically exposed for external access through two methods:

  1. Window object: Available as window['FIELD_ID_editor'] where FIELD_ID is the field’s HTML ID

  2. DOM element: Available as container.jsonEditor property on the widget’s container element

Example usage for external JavaScript access:

// Access via window object
var editor = window['id_jsonfield_editor'];
editor.set({'key': 'new value'});

// Access via DOM element
var container = document.getElementById('id_jsonfield');
var editor = container.jsonEditor;
editor.set({'key': 'new value'});

This allows you to programmatically call JsonEditor methods like set(), get(), update(), etc. from custom JavaScript code running in your admin pages or forms.

JSONEditorWidget widget

Before:

https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_0.png

After:

https://raw.githubusercontent.com/jmrivas86/django-json-widget/master/imgs/jsonfield_1.png

Development Guide

Read the contribution guide.

Credits

Tools used in rendering this package:

Changelog

2.1.1 (2025-12-12)

  • Issue #108: respect Django admin color scheme setting for JSON editor.

2.1.0 (2025-10-24)

  • Issue #114: expose editor instance to window object and DOM element.

2.0.4 (2025-10-11)

  • Fix dark mode CSS support #107

2.0.3 (2025-07-29)

2.0.2 (2025-07-28)

  • Fix Version 2.0.1 causes rendering HTML scripts issue #80

2.0.1 (2024-03-02) ——————=

  • Fixed Version 2.0.0 causes issues with Django 4.x due to missing sourcemaps issue #83

2.0.0 (2024-03-24)

  • Fix default paths for static files #53

  • Stop declaring support for Django versions before 3.2 #65

  • Avoid HTML injection via unsafe JSON injection #64

  • Remove source map reference from JS bundle #70

  • Add dark mode CSS support #82

  • Updated documentation

1.1.1 (2021-02-17)

  • Fix for issue #51, updates the bundled libs to 9.1.9 and additional notes for Django 3.1 changes

1.1.0 (2021-02-05)

  • Added functionality to override version of JSONEditor to use

  • update readme for django 3.1

1.0.1 (2020-04-17)

  • Stop resolving paths to the static files

1.0.0 (2020-01-16)

  • Update Makefile

  • Make Stable the project

0.3.0 (2020-01-16)

  • Update requirements.txt

  • Fixed static to work with CDN tools like django-storages

  • Make widget more configurable

  • Fixed an incompatibility with Python 2.7

  • update jsoneditor to latest version

Release files for django-json-widget 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-json-widget 2.1.1
File Size Uploaded
django_json_widget-2.1.1.tar.gz 384.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-json-widget 2.1.1
File Interpreter ABI Platform
django_json_widget-2.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 677.7 kB

Release files / django_json_widget-2.1.1.tar.gz

Download URL django_json_widget-2.1.1.tar.gz
Size 384.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dc8102e2fa9accd0f661ea1988c9389f8fbbcb8a4bb9cbfb8fa0525b3c1265c1
BLAKE2b-256 checksum
How to use checksums
f930923ff229ee284bf2fac7a289ca446fb2725d94b2a34c7cb006c4f811e6c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.13.6

Release files / django_json_widget-2.1.1-py2.py3-none-any.whl

Download URL django_json_widget-2.1.1-py2.py3-none-any.whl
Size 293.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2fa3d6fb6dba9436a29ad2cee23fa794381f54a6678ec7d74e990ae081d9800b
BLAKE2b-256 checksum
How to use checksums
196abdbcc079d11d312e463565819089fe83ae6c7f17f274effa4777ca069f64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.13.6

Release history Release notifications | RSS feed

This release

2.1.1 This release

2 release files

2.1.0

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

1 release file

2.0.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.3.0

1 release file

0.2.0

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page