[Python-checkins] cpython (2.7): explain json.dumps for non-string keys in dicts. closes issue6566. Patch

senthil.kumaran python-checkins at python.org
Sat Mar 17 08:41:25 CET 2012


http://hg.python.org/cpython/rev/7c818b4cd98a
changeset:   75777:7c818b4cd98a
branch:      2.7
parent:      75768:55993cd25564
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Sat Mar 17 00:37:38 2012 -0700
summary:
   explain json.dumps for non-string keys in dicts. closes issue6566. Patch contributed Kirubakaran Athmanathan

files:
  Doc/library/json.rst |  8 ++++++++
  1 files changed, 8 insertions(+), 0 deletions(-)


diff --git a/Doc/library/json.rst b/Doc/library/json.rst
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -170,6 +170,14 @@
    :class:`unicode` instance.  The other arguments have the same meaning as in
    :func:`dump`.
 
+   .. note::
+
+      Keys in key/value pairs of JSON are always of the type :class:`str`. When
+      a dictionary is converted into JSON, all the keys of the dictionary are
+      coerced to strings. As a result of this, if a dictionary is convered
+      into JSON and then back into a dictionary, the dictionary may not equal
+      the original one. That is, ``loads(dumps(x)) != x`` if x has non-string
+      keys.
 
 .. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list