* Fix-up a TODO (support the sort_key option).

* Fix an error where True/False were being written-out
  as title-cased strings when used a dictionary keys.
* Speed-up iteration over dicts by looping over items()
  rather than keys() followed by value lookups.
* TODO:  sort only by keys, not keys and values.
This commit is contained in:
Raymond Hettinger 2009-05-27 09:58:34 +00:00
parent 81c0dcee65
commit bcf6f92dc5
3 changed files with 47 additions and 22 deletions

View file

@ -43,3 +43,8 @@ class TestEncodeBaseStringAscii(TestCase):
items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)]
s = json.dumps(OrderedDict(items))
self.assertEqual(s, '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}')
def test_sorted_dict(self):
items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)]
s = json.dumps(dict(items), sort_keys=True)
self.assertEqual(s, '{"five": 5, "four": 4, "one": 1, "three": 3, "two": 2}')