Enabling sorted json keys by default

52 views
Skip to first unread message

David Aguilar

unread,
Oct 2, 2010, 4:54:13 PM10/2/10
to John Paulett, ricopan, jsonp...@googlegroups.com, dav...@gmail.com
I pushed two commits to my fork's master branch:

git://github.com/davvid/jsonpickle.git

This enables sorted keys by default for the
'simplejson' backends. Adding the same for
the others should be trivial.

John, can you merge my master, please :-)


From 7106c79acf7d5e606c6378b890ddbe03912a6c0a Mon Sep 17 00:00:00 2001
From: David Aguilar <dav...@gmail.com>
Date: Sat, 2 Oct 2010 08:11:10 -0700
Subject: [PATCH 1/2] tests/runtests.py: Insert into the sys.path, not append

Insert the jsonpickle sandbox at the front of sys.path
otherwise system-installed versions can be picked up
by the tests.

Signed-off-by: David Aguilar <dav...@gmail.com>
---
tests/runtests.py | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tests/runtests.py b/tests/runtests.py
index 4a5b311..e2ba356 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -9,7 +9,9 @@

import os
import sys
-sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+
+testdir = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(1, os.path.dirname(testdir))

import unittest

--
1.7.3.1.50.g1e633


From 186a038cccd549b2aad42eaf8a8fcd38182f7931 Mon Sep 17 00:00:00 2001
From: David Aguilar <dav...@gmail.com>
Date: Sat, 2 Oct 2010 08:13:57 -0700
Subject: [PATCH 2/2] jsonpickle/__init__.py: Enable sorted keys by default

Enable sorted keys for json/simplejson backends.
We should do this for the other backends too.

Signed-off-by: David Aguilar <dav...@gmail.com>
---
jsonpickle/__init__.py | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/jsonpickle/__init__.py b/jsonpickle/__init__.py
index 22161dd..ea5ca6d 100644
--- a/jsonpickle/__init__.py
+++ b/jsonpickle/__init__.py
@@ -87,7 +87,12 @@ class JSONPluginMgr(object):
self._decoders = {}

## Options to pass to specific encoders
- self._encoder_options = {}
+ json_opts = ((), {'sort_keys': True})
+ self._encoder_options = {
+ 'json': json_opts,
+ 'simplejson': json_opts,
+ 'django.util.simplejson': json_opts,
+ }

## The exception class that is thrown when a decoding error occurs
self._decoder_exceptions = {}
--
1.7.3.1.50.g1e633


--

David

John Paulett

unread,
Oct 4, 2010, 8:55:53 PM10/4/10
to David Aguilar, ricopan, jsonp...@googlegroups.com
Thanks! Done and pushed.
Reply all
Reply to author
Forward
0 new messages