Django JSON Widget

2.1.1 · active · verified Sun Apr 12

Django JSON Widget provides an alternative, user-friendly widget for editing Django's JSONField, featuring syntax highlighting, automatic indentation, and validation. It leverages the JSONEditor JavaScript library to enhance the default Django form experience. The library is actively maintained, with frequent updates, and is currently at version 2.1.1.

Warnings

Install

Imports

Quickstart

To quickly integrate `django-json-widget` into your Django admin, add `django_json_widget` to your `INSTALLED_APPS` and then override the default widget for `JSONField` in your `admin.py` using `formfield_overrides`.

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

# models.py (example)
class MyModel(models.Model):
    name = models.CharField(max_length=255)
    data = models.JSONField(default=dict)

    def __str__(self):
        return self.name

# admin.py (example)
from django.contrib import admin
from .models import MyModel
from django_json_widget.widgets import JSONEditorWidget

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    list_display = ('name',)
    formfield_overrides = {
        models.JSONField: {'widget': JSONEditorWidget},
    }

# Alternatively, in a custom form:
# from django import forms
# from .models import MyModel
# from django_json_widget.widgets import JSONEditorWidget
#
# class MyForm(forms.ModelForm):
#     class Meta:
#         model = MyModel
#         fields = ('name', 'data')
#         widgets = {
#             'data': JSONEditorWidget,
#         }

view raw JSON →