From: Senthil Kumaran Date: Sat, 17 Mar 2012 07:37:38 +0000 (-0700) Subject: explain json.dumps for non-string keys in dicts. closes issue6566. Patch contributed... X-Git-Tag: v2.7.4rc1~958^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e3d73544ad74eeb72e3e51794329b6bfa683ac55;p=python explain json.dumps for non-string keys in dicts. closes issue6566. Patch contributed Kirubakaran Athmanathan --- diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 546a09d69b..6d4497f224 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -170,6 +170,14 @@ Basic Usage :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]]]]]]]])