* 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.
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 3c306ab..2beb10e 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -233,7 +233,7 @@
if (_one_shot and c_make_encoder is not None
- and not self.indent and not self.sort_keys):
+ and not self.indent):
_iterencode = c_make_encoder(
markers, self.default, _encoder, self.indent,
self.key_separator, self.item_separator, self.sort_keys,
diff --git a/Lib/json/tests/test_encode_basestring_ascii.py b/Lib/json/tests/test_encode_basestring_ascii.py
index 8711469..dbcb09a 100644
--- a/Lib/json/tests/test_encode_basestring_ascii.py
+++ b/Lib/json/tests/test_encode_basestring_ascii.py
@@ -43,3 +43,8 @@
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}')