#9233: Fix json.loads({}) to return a dict (instead of a list), when _json is not available.
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
index b9745f7..eeebf45 100644
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -161,6 +161,12 @@
nextchar = s[end:end + 1]
# Trivial empty object
if nextchar == '}':
+ if object_pairs_hook is not None:
+ result = object_pairs_hook(pairs)
+ return result, end
+ pairs = {}
+ if object_hook is not None:
+ pairs = object_hook(pairs)
return pairs, end + 1
elif nextchar != '"':
raise ValueError(errmsg("Expecting property name", s, end))
diff --git a/Lib/json/tests/test_decode.py b/Lib/json/tests/test_decode.py
index 6afafe6..95088b4 100644
--- a/Lib/json/tests/test_decode.py
+++ b/Lib/json/tests/test_decode.py
@@ -23,6 +23,11 @@
rval = json.loads('{ "key" : "value" , "k":"v" }')
self.assertEqual(rval, {"key":"value", "k":"v"})
+ def test_empty_objects(self):
+ self.assertEqual(json.loads('{}'), {})
+ self.assertEqual(json.loads('[]'), [])
+ self.assertEqual(json.loads('""'), "")
+
def test_object_pairs_hook(self):
s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
diff --git a/Misc/NEWS b/Misc/NEWS
index 4d43f55..4718a69 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -51,7 +51,10 @@
Library
-------
-- Issue #11703 - urllib2.geturl() does not return correct url when the original
+- Issue #9233: Fix json.loads('{}') to return a dict (instead of a list), when
+ _json is not available.
+
+- Issue #11703: urllib2.geturl() does not return correct url when the original
url contains #fragment.
- Issue #10019: Fixed regression in json module where an indent of 0 stopped