Registry / web-framework / django-jsonform

django-jsonform

JSON →
library2.23.2pypypi✓ verified 86d ago

django-jsonform is a Django library that provides a user-friendly form interface for editing JSON data directly within the Django admin. It leverages JSON schema to define the structure of the JSON data, automatically generating dynamic forms for creating and editing. The library also supports PostgreSQL's ArrayField with multiple levels of nesting. As of version 2.23.2, it maintains an active development pace with several releases per year, addressing bugs and introducing new features.

pip install django-jsonform
INSTALL
IMPORT
SIG · DJANGO-JSONFORM
D
django-jsonform
web-frameworkpythonv2.23.2
Install
3.5s avg
Import
625ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.23.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.661s · 66.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.5s · import 0.589s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSONField
from django_jsonform.models.fields import JSONField
JSONFormWidget
from django_jsonform.widgets import JSONFormWidget
Primarily used internally by JSONField, but can be imported for custom form setups.
JSONSchemaValidationError
from django_jsonform.exceptions import JSONSchemaValidationError
Required for advanced custom validation to provide field-specific error messages.
ErrorMap
from django_jsonform.utils import ErrorMap
Used in advanced custom validation for mapping errors to specific schema paths.

To quickly integrate `django-jsonform`, define a `JSONField` in your Django model with a corresponding JSON schema. Then, register your model with the Django admin. The library will automatically render a dynamic form based on your schema. Remember to add `django_jsonform` to your `INSTALLED_APPS` and run `collectstatic` for the JavaScript assets to load correctly.

from django.db import models from django.contrib import admin from django_jsonform.models.fields import JSONField # models.py class ShoppingList(models.Model): name = models.CharField(max_length=255) items = JSONField( schema={ 'type': 'array', 'title': 'Shopping Items', 'items': { 'type': 'dict', 'keys': { 'item_name': {'type': 'string', 'title': 'Item Name'}, 'quantity': {'type': 'integer', 'title': 'Quantity', 'minimum': 1} } } }, help_text='A list of items for shopping.' ) def __str__(self): return self.name # admin.py # Ensure 'django_jsonform' is in INSTALLED_APPS in settings.py @admin.register(ShoppingList) class ShoppingListAdmin(admin.ModelAdmin): list_display = ('name',) # To see the form in action: # 1. Add 'django_jsonform' to INSTALLED_APPS in your settings.py # 2. Run 'python manage.py makemigrations' and 'python manage.py migrate' # 3. Run 'python manage.py createsuperuser' and log in to the Django admin.
Debug
Known issues
gotchaAfter installing or upgrading, you must run `python manage.py collectstatic` in your production environment (and often development) to ensure the necessary JavaScript and CSS files are available. Failure to do so will result in the JSON form not rendering correctly or at all.
fix
Run `python manage.py collectstatic` after installation or any upgrade.
affects: All versions
gotchaChanging the JSON schema for an existing `JSONField` can lead to discrepancies with pre-existing JSON data. `django-jsonform` does not provide an automatic data migration mechanism; you'll need to manually migrate or transform old JSON data to conform to the new schema, typically from a Django shell.
fix
Manually update existing JSON data in the database to match the new schema structure, or implement custom data migration scripts.
affects: All versions
deprecatedThe `JSONFORM_UPLOAD_HANDLER` setting for file uploads was deprecated in version 2.11. It is kept for backward compatibility but will be removed in future versions. You should now use the `FILE_HANDLER` key within the main `DJANGO_JSONFORM` settings dictionary.
fix
Update your `settings.py` to use `DJANGO_JSONFORM = {'FILE_HANDLER': 'your_app.views.your_handler_view_url'}` instead of `JSONFORM_UPLOAD_HANDLER`.
affects: >=2.11
breakingWhen implementing custom validation (e.g., using `JSONSchemaValidationError`), from version 2.15.0 onwards, you should use the `ErrorMap` helper class to construct the `error_map` object. This change was introduced to properly support schema object keys (field names) containing hyphens.
fix
Refactor custom validation logic to utilize `django_jsonform.utils.ErrorMap` for building error dictionaries.
affects: >=2.15.0
gotchaVersions prior to 2.21.5 had a bug due to a missing UUID import, which could cause a `NameError` exception when using UUID-related fields.
fix
Upgrade to `django-jsonform` version 2.21.5 or newer.
affects: <2.21.5
gotchaIn versions prior to 2.21.3, there were layout issues in Django 4.x, causing the form to render very narrowly in the admin interface.
fix
Upgrade to `django-jsonform` version 2.21.3 or newer to resolve Django 4.x layout problems.
affects: <2.21.3
Errors
Common errors & fixes
Schema and data structure do not match
This error occurs when the JSON schema defined for a field does not align with the actual structure or types of the JSON data being saved or edited, often after the schema has been changed for an existing field with pre-existing data.
fix
Manually migrate the existing JSON data to conform to the new schema, or ensure that new data strictly adheres to the defined schema. The library does not automatically migrate existing JSON data when the schema changes.
ModuleNotFoundError: No module named 'django_jsonform'
This error typically indicates that the 'django_jsonform' package is either not installed, not correctly added to `INSTALLED_APPS` in your Django settings, or there's an issue with your Python environment's path.
fix
First, ensure the package is installed: `pip install django-jsonform`. Then, add `'django_jsonform'` to your `INSTALLED_APPS` in `settings.py`.
django_jsonforms are not displayed in the browser
The JSON form widget (the front-end editor) is not rendering correctly in the browser, often because Django's static files (JavaScript, CSS) for `django-jsonform` have not been collected or are not being served.
fix
Run `python manage.py collectstatic` to gather all static files, and ensure your Django project is configured to serve static files correctly, especially in a production environment. Clear your browser cache during development.
ImproperlyConfigured('ArrayField requires psycopg2 to be installed.')
This error occurs when attempting to use `django-jsonform`'s `ArrayField` (which is designed for PostgreSQL's ArrayField) without having the `psycopg2` adapter installed, which is necessary for PostgreSQL database interactions.
fix
Install the `psycopg2` Python package: `pip install psycopg2-binary`.
Upgrade
Version history
2.23.2latest on PyPI · released Jan 29, 2025
Audit
Dependencies
DjangorequiredCore framework dependency for integration.
Agent activity
8 hits · last 30 days
node
8
Resources
django-jsonform — pip install django-jsonform · libregistry