Search code examples
djangodjango-jsonfield

Django jsonfields ValidationError: [u'Enter valid JSON'] upon upgrade from 1.7 to 1.9


I'm upgrading django from 1.7 to 1.9 by means of replacing packages, installed in system (Debian 8) via apt-get with packages, installed via pip.

So, I installed jsonfield package from pip instead of apt's good old python-django-jsonfield and tried running unittests.

All my jsonfields, defined as jsonfield.JSONField(), fail the tests with message:

ValidationError: [u'Enter valid JSON']

Everything worked fine before. Any ideas, what's changed?


Solution

  • With Django 1.7 I used jsonfield 0.9, but now I installed jsonfield 1 and there's a significant difference between them. Unfortunately, jsonfield 0.9 makes use of simplejson (from django.utils import simplejson as json), which is not available in Django 1.9.

    As I'm using Django 1.9 anyways and there's built-in support for JSONField in django.contrib.postgres.fields, I switched to it. I solved my problems by adding null=True, blank=True to JSONField definition:

    JSONField(null=True, blank=True)