{"id":8952,"library":"django-jsoneditor","title":"Django JSON Editor","description":"Django-JSONEditor is an online structured JSON input widget for Django that enhances the editing experience for various JSONField implementations. It integrates the core JSONEditor JavaScript library (from jsoneditoronline.org) into Django's admin interface and forms. The library is currently at version 0.2.4, with its last release in February 2023, and shows an active but somewhat dated approach to JSON editing within the Django ecosystem, with discussions around newer alternatives.","status":"active","version":"0.2.4","language":"en","source_language":"en","source_url":"https://github.com/nnseva/django-jsoneditor","tags":["django","json","editor","admin","widget","jsonfield"],"install":[{"cmd":"pip install django-jsoneditor","lang":"bash","label":"Install stable version from PyPI"}],"dependencies":[{"reason":"Core framework integration.","package":"Django"},{"reason":"Provides the underlying JSONField functionality for Django >= 1.9; django-jsoneditor provides the widget only. Can also be a third-party JSONField.","package":"django.contrib.postgres.fields.JSONField","optional":true}],"imports":[{"note":"The top-level package name in `INSTALLED_APPS` and imports is 'jsoneditor', not 'django_jsoneditor'.","wrong":"from django_jsoneditor.forms import JSONEditor","symbol":"JSONEditor","correct":"from jsoneditor.forms import JSONEditor"},{"note":"The app name to register in Django settings is 'jsoneditor', not 'django_jsoneditor'.","wrong":"INSTALLED_APPS = [\n    # ...\n    'django_jsoneditor',\n    # ...\n]","symbol":"INSTALLED_APPS","correct":"INSTALLED_APPS = [\n    # ...\n    'jsoneditor',\n    # ...\n]"},{"note":"For `formfield_overrides`, you typically reference Django's native `JSONField` or the one from your model's source. The `jsoneditor.fields` module provides specific, 'fixed' JSONField implementations for older Django versions or third-party JSONFields, which is a less common direct import for basic usage.","wrong":"from jsoneditor.fields.postgres_jsonfield import JSONField # unless explicitly replacing the original","symbol":"JSONField","correct":"from django.db import models # then models.JSONField for formfield_overrides"}],"quickstart":{"code":"# settings.py\nINSTALLED_APPS = [\n    # ...\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'jsoneditor', # Add this line\n    # ...\n]\n\n# models.py (Example using Django's native JSONField)\nfrom django.db import models\n\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\nfrom django.contrib import admin\nfrom django.db import models\nfrom .models import MyModel\nfrom jsoneditor.forms import JSONEditor\n\n@admin.register(MyModel)\nclass MyModelAdmin(admin.ModelAdmin):\n    formfield_overrides = {\n        models.JSONField: {'widget': JSONEditor},\n    }\n","lang":"python","description":"To quickly integrate `django-jsoneditor` into your Django admin, add `jsoneditor` to your `INSTALLED_APPS` and then override the default widget for `JSONField` in your `admin.py` using `formfield_overrides`. Ensure you have an appropriate `JSONField` defined in your model, such as `django.db.models.JSONField` (for Django 3.1+ or with PostgreSQL) or a compatible third-party `JSONField`."},"warnings":[{"fix":"Ensure your model's JSON field is defined using `django.db.models.JSONField` or a compatible alternative like `django-jsonfield`.","message":"This library only provides a widget for editing JSON data. It does NOT provide a `JSONField` itself. You must use Django's built-in `django.db.models.JSONField` (available from Django 3.1+, or with `django.contrib.postgres` for older versions) or a compatible third-party `JSONField` package.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For basic use cases, this may not be an issue. For highly interactive, large-document, or modern UI needs, consider evaluating `django-svelte-jsoneditor` or other alternatives.","message":"The underlying JavaScript JSON Editor library (which uses the Ace editor) is considered by some to be 'out-of-date' and can experience issues with very large JSON documents (e.g., crashing, reverting to `TextArea` in read-only mode). Newer alternatives like `django-svelte-jsoneditor` exist.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the GitHub README's 'Custom JSONEditor initialization' section for detailed steps on setting `JSON_EDITOR_INIT_JS` and modifying the `init.js` file.","message":"Customizing the JSON Editor's JavaScript initialization (e.g., setting default modes or options) requires copying the library's `init.js` file to your static storage and configuring `JSON_EDITOR_INIT_JS` in your Django settings to point to your modified copy.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that `pip install django-jsoneditor` completed successfully, and ensure `'jsoneditor'` is present in your `INSTALLED_APPS` list in `settings.py`.","cause":"The `jsoneditor` application is either not installed in your Python environment or not correctly added to your `INSTALLED_APPS` in Django's settings.py.","error":"ModuleNotFoundError: No module named 'jsoneditor'"},{"fix":"This usually requires custom JavaScript to ensure the JSON Editor instance updates its associated form field before the form is submitted. The underlying `jsoneditor` library exposes an instance (e.g., `window['FIELD_ID_editor']` or `container.jsonEditor`) that can be used to `get()` the current value and `set()` it on the hidden form input.","cause":"This often occurs because the JavaScript editor's content isn't properly transferred back to the hidden form field (e.g., a `<textarea>`) that Django expects to receive the data upon form submission.","error":"Changes made in the JSON Editor widget are not saved in Django Admin."},{"fix":"Ensure `django.contrib.staticfiles` is configured correctly and `python manage.py collectstatic` has been run. If used in custom forms, you may need to manually include the widget's media assets in your template, or ensure your form renders its media correctly (e.g., `{{ form.media }}`).","cause":"The static files for the JSON Editor widget (JavaScript and CSS) might not be correctly served or included when using the widget outside of Django's admin interface, or due to incorrect `STATICFILES_FINDERS` configuration.","error":"JSONEditor library not loaded in form assets / JavaScript errors related to JSONEditor not being defined on non-admin pages."}]}