Matthew Schinckel  committed 6fd40e0

Experimental support for using OrderedDict.
Personally, I'm not sure this is necessary, especially as
most languages don't have ordered hashes by default,
especially JS, which is likely to be where the data has
come from or is going to.

  • Participants
  • Parent commits f92caa9
  • Branches ordered-dict

Comments (0)

Files changed (3)

File jsonfield/

 from __future__ import unicode_literals
-from django.core.exceptions import ValidationError
+from decimal import Decimal
+import datetime
+from django.core.exceptions import ValidationError, ImproperlyConfigured
 from django.conf import settings
 from django.db import models, DatabaseError, transaction
 from django.utils import simplejson as json
 from django.utils.translation import ugettext_lazy as _
 from django.utils import six
-from decimal import Decimal
-import datetime
+# Need to do this after importing ImproperlyConfigured
+    from collections import OrderedDict
+except ImportError:
+    try:
+        from ordereddict import OrderedDict
+    except ImportError:
+        raise ImproperlyConfigured('You must install ordereddict under python2.6')
 from .utils import default
 from .widgets import JSONWidget
 from .forms import JSONFormField
                 if self.blank:
                     return ""
-                value = json.loads(value)
+                value = json.loads(value, object_pairs_hook=OrderedDict)
             except ValueError:
                 msg = self.error_messages['invalid'] % value
                 raise ValidationError(msg)

File jsonfield/

             return value
         if isinstance(value, basestring):
+            from .fields import OrderedDict
-                return json.loads(value)
+                return json.loads(value, object_pairs_hook=OrderedDict)
             except Exception as exc:
                 raise forms.ValidationError(
                     'JSON decode error: %s' % (unicode(exc),)
+  {[testenv]deps}
+  ordereddict
+  simplejson
+  {[testenv]deps}
+  simplejson