{"id":13725647,"url":"https://github.com/rpkilby/jsonfield","last_synced_at":"2025-12-12T01:03:19.096Z","repository":{"id":560369,"uuid":"191265","full_name":"rpkilby/jsonfield","owner":"rpkilby","description":"A reusable Django model field for storing ad-hoc JSON data","archived":false,"fork":false,"pushed_at":"2023-07-24T09:17:20.000Z","size":223,"stargazers_count":1162,"open_issues_count":13,"forks_count":270,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-06T23:31:33.688Z","etag":null,"topics":["django","json","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rpkilby.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2009-05-03T03:42:01.000Z","updated_at":"2025-02-23T12:14:24.000Z","dependencies_parsed_at":"2024-01-08T23:03:12.894Z","dependency_job_id":"9e32ca0c-4c4c-405a-9f2b-e3bae7ad9d0b","html_url":"https://github.com/rpkilby/jsonfield","commit_stats":{"total_commits":299,"total_committers":53,"mean_commits":"5.6415094339622645","dds":0.6254180602006689,"last_synced_commit":"cb749a8e5de019c88349a184c2863429923b767f"},"previous_names":["bradjasper/django-jsonfield","dmkoch/django-jsonfield"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpkilby%2Fjsonfield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpkilby%2Fjsonfield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpkilby%2Fjsonfield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpkilby%2Fjsonfield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rpkilby","download_url":"https://codeload.github.com/rpkilby/jsonfield/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248017115,"owners_count":21034036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","json","python"],"created_at":"2024-08-03T01:02:30.160Z","updated_at":"2025-12-12T01:03:19.089Z","avatar_url":"https://github.com/rpkilby.png","language":"Python","funding_links":[],"categories":["Python","Django Utilities"],"sub_categories":[],"readme":"jsonfield\n=========\n\n.. image:: https://github.com/rpkilby/jsonfield/actions/workflows/main.yml/badge.svg\n  :target: https://github.com/rpkilby/jsonfield/actions/workflows/main.yml\n.. image:: https://codecov.io/gh/rpkilby/jsonfield/graph/badge.svg\n  :target: https://codecov.io/gh/rpkilby/jsonfield\n.. image:: https://img.shields.io/pypi/l/jsonfield.svg\n  :target: https://pypi.org/project/jsonfield\n.. image:: https://img.shields.io/pypi/v/jsonfield.svg\n  :target: https://pypi.org/project/jsonfield\n.. image:: https://img.shields.io/pypi/pyversions/jsonfield.svg\n  :target: https://pypi.org/project/jsonfield\n\n**jsonfield** is a reusable model field that allows you to store validated JSON, automatically handling\nserialization to and from the database. To use, add ``jsonfield.JSONField`` to one of your models.\n\n\nDeprecation \u0026 Migration to Django's native ``JSONField``\n--------------------------------------------------------\n\nDjango 3.1 `introduced`_ a native ``JSONField`` that supports all database backends. As such, this package is\nconsidered deprecated and will be archived in the future. Existing projects should migrate to Django's implemenation.\n\n.. _introduced: https://docs.djangoproject.com/en/stable/releases/3.1/#jsonfield-for-all-supported-database-backends\n\n\nMigrating from ``jsonfield.JSONField`` to ``models.JSONField`` *should* generally be straightforward. After swapping\nfield classes, ``python manage.py migrate`` will generate ``AlterField`` operations that should correctly migrate\nyour field data. However, if this does not work for your case, you will instead need to create a data migration.\nThe process will roughly look like:\n\n* Rename ``\u003cfield\u003e`` to ``old_\u003cfield\u003e``, create migration.\n* Add a nullable ``\u003cfield\u003e = models.JSONField(null=True, ...)``, create migration.\n* Create an empty migration file, add  ``RunPython`` operation that reserializes\n  the ``old_\u003cfield\u003e`` data into the new ``\u003cfield\u003e``.\n* Update ``\u003cfield\u003e`` to not nullable, delete ``old_\u003cfield\u003e``, create migration.\n* Manually combine the operations into a single migration file.\n\nExamples can be found in the `migration-example`_ project.\n\n.. _migration-example: https://github.com/rpkilby/jsonfield/tree/master/migration-example/\n\n\nInstallation\n------------\n\n.. code-block:: python\n\n    pip install jsonfield\n\n\nUsage\n-----\n\n.. code-block:: python\n\n    from django.db import models\n    from jsonfield import JSONField\n\n    class MyModel(models.Model):\n        json = JSONField()\n\n\nQuerying\n--------\n\nAs stated above, ``JSONField`` is not intended to provide extended querying capabilities.\nThat said, you may perform the same basic lookups provided by regular text fields (e.g.,\n``exact`` or ``regex`` lookups). Since values are stored as serialized JSON, it is highly\nrecommended that you test your queries to ensure the expected results are returned.\n\n\nHandling null values\n--------------------\n\nA model field's ``null`` argument typically controls whether null values may be stored in\nits column by setting a not-null constraint. However, because ``JSONField`` serializes its\nvalues (including nulls), this option instead controls *how* null values are persisted. If\n``null=True``, then nulls are **not** serialized and are stored as a null value in the\ndatabase. If ``null=False``, then the null is instead stored in its serialized form.\n\nThis in turn affects how null values may be queried. Both fields support exact matching:\n\n.. code-block:: python\n\n    MyModel.objects.filter(json=None)\n\nHowever, if you want to use the ``isnull`` lookup, you must set ``null=True``.\n\n.. code-block:: python\n\n    class MyModel(models.Model):\n        json = JSONField(null=True)\n\n    MyModel.objects.filter(json__isnull=True)\n\nNote that as ``JSONField.null`` does not prevent nulls from being stored, achieving this\nmust instead be handled with a validator.\n\n\nAdvanced Usage\n--------------\n\nBy default python deserializes json into dict objects. This behavior differs from the standard json\nbehavior  because python dicts do not have ordered keys. To overcome this limitation and keep the\nsort order of OrderedDict keys the deserialisation can be adjusted on model initialisation:\n\n.. code-block:: python\n\n    import collections\n\n    class MyModel(models.Model):\n        json = JSONField(load_kwargs={'object_pairs_hook': collections.OrderedDict})\n\n\nOther Fields\n------------\n\n**jsonfield.JSONCharField**\n\nSubclasses **models.CharField** instead of **models.TextField**.\n\n\nRunning the tests\n-----------------\n\nThe test suite requires ``tox``.\n\n.. code-block:: shell\n\n    $ pip install tox\n\n\nThen, run the ``tox`` command, which will run all test jobs.\n\n.. code-block:: shell\n\n    $ tox\n\nOr, to test just one job (for example Django 5.2 on Python 3.13):\n\n.. code-block:: shell\n\n    $ tox -e py313-django52\n\n\nRelease Process\n---------------\n\n* Update changelog\n* Update package version in setup.py\n* Check supported versions in setup.py and readme\n* Create git tag for version\n* Upload release to PyPI test server\n* Upload release to official PyPI server\n\n.. code-block:: shell\n\n    $ pip install -U pip setuptools wheel twine\n    $ rm -rf dist/ build/\n    $ python setup.py sdist bdist_wheel\n    $ twine upload -r test dist/*\n    $ twine upload dist/*\n\n\nChanges\n-------\n\nTake a look at the `changelog`_.\n\n.. _changelog: https://github.com/rpkilby/jsonfield/blob/master/CHANGES.rst\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpkilby%2Fjsonfield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frpkilby%2Fjsonfield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpkilby%2Fjsonfield/lists"}