[issue21092] json serializer implicitly stringifies non-string keys
New submission from Chris Rebert: Python 3.3.4 (default, Feb 21 2014, 18:00:34) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin Type "help", "copyright", "credits" or "license" for more information.
from json import dumps dumps({True: True, False: False, None: None, 42: 42}) '{"false": false, "true": true, "42": 42, "null": null}'
This implicit stringification of non-string dictionary keys does not currently appear to be documented. ---------- assignee: docs@python components: Documentation messages: 215105 nosy: cvrebert, docs@python priority: normal severity: normal status: open title: json serializer implicitly stringifies non-string keys versions: Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue21092> _______________________________________
Berker Peksag added the comment:
This implicit stringification of non-string dictionary keys does not currently appear to be documented.
I think this is part of the JSON spec. See http://json.org/object.gif for example. Also, this is already documented in the json.dumps() documentation:
Keys in key/value pairs of JSON are always of the type str. When a dictionary is converted into JSON, all the keys of the dictionary are coerced to strings.
http://docs.python.org/3.4/library/json.html#json.dumps ---------- nosy: +berker.peksag _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue21092> _______________________________________
Changes by Brett Cannon <brett@python.org>: ---------- resolution: -> invalid status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue21092> _______________________________________
Roundup Robot added the comment: New changeset 36099a05d76a by Mark Dickinson in branch 'default': Issue #21092: Merge from 3.4. https://hg.python.org/cpython/rev/36099a05d76a ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue21092> _______________________________________
Mark Dickinson added the comment: Sorry; that last commit message should have been for #21902. ---------- nosy: +mark.dickinson _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue21092> _______________________________________
participants (5)
-
Berker Peksag
-
Brett Cannon
-
Chris Rebert
-
Mark Dickinson
-
Roundup Robot