{"id":4930,"library":"django-json-widget","title":"Django JSON Widget","description":"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.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/jmrivas86/django-json-widget","tags":["django","json","widget","admin","jsonfield"],"install":[{"cmd":"pip install django-json-widget","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"The widget is for Django's JSONField. Compatible with Django 3.2, 4.2, 5.0, 5.2 as per PyPI classifiers.","package":"Django","optional":false}],"imports":[{"note":"Used to override the default widget for JSONField in Django forms or admin.","symbol":"JSONEditorWidget","correct":"from django_json_widget.widgets import JSONEditorWidget"}],"quickstart":{"code":"from django.contrib import admin\nfrom django.db import models\nfrom django_json_widget.widgets import JSONEditorWidget\n\n# models.py (example)\nclass MyModel(models.Model):\n    name = models.CharField(max_length=255)\n    data = models.JSONField(default=dict)\n\n    def __str__(self):\n        return self.name\n\n# admin.py (example)\nfrom django.contrib import admin\nfrom .models import MyModel\nfrom django_json_widget.widgets import JSONEditorWidget\n\n@admin.register(MyModel)\nclass MyModelAdmin(admin.ModelAdmin):\n    list_display = ('name',)\n    formfield_overrides = {\n        models.JSONField: {'widget': JSONEditorWidget},\n    }\n\n# Alternatively, in a custom form:\n# from django import forms\n# from .models import MyModel\n# from django_json_widget.widgets import JSONEditorWidget\n#\n# class MyForm(forms.ModelForm):\n#     class Meta:\n#         model = MyModel\n#         fields = ('name', 'data')\n#         widgets = {\n#             'data': JSONEditorWidget,\n#         }","lang":"python","description":"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`."},"warnings":[{"fix":"Replace `JSONEditorWidget(mode='tree')` with `JSONEditorWidget(options={'mode': 'tree'})`.","message":"The `mode` argument for `JSONEditorWidget` is deprecated since version 0.2.0. Instead, specify the editor mode (e.g., 'tree', 'code', 'form') via the `options` dictionary, which accepts arguments directly from the underlying JSON Editor JavaScript library.","severity":"deprecated","affected_versions":"0.2.0+"},{"fix":"Review and update your Django project's CSP to allow for the necessary inline scripts or consider alternative methods for integrating the widget if strict CSP is required.","message":"Using inline scripts in the widget might conflict with Content Security Policies (CSP) if not properly configured, potentially leading to script blocking and functionality issues.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Test thoroughly when using with inlines or custom admin themes. For inlines, a custom form for the inline might be needed. For admin themes, custom CSS overrides may be required.","message":"There are reported issues with the widget not functioning correctly or rendering improperly when used within Django's `TabularInline` or when integrated with third-party admin themes like `Grappelli`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `django-json-widget` version 2.0.0 or higher to resolve static file and sourcemap issues with Django 4.x and newer.","message":"Prior to version 2.0.0, users experienced issues with Django 4.x due to missing sourcemaps and incorrect default paths for static files, leading to improper rendering or functionality.","severity":"breaking","affected_versions":"< 2.0.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}