This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: json serializer implicitly stringifies non-string keys
Type: Stage:
Components: Documentation Versions: Python 3.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: berker.peksag, cvrebert, docs@python, mark.dickinson, python-dev
Priority: normal Keywords:

Created on 2014-03-29 02:02 by cvrebert, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg215105 - (view) Author: Chris Rebert (cvrebert) * Date: 2014-03-29 02:02
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.
msg215129 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-03-29 13:34
> 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 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.
msg233847 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-11 13:23
New changeset 36099a05d76a by Mark Dickinson in branch 'default':
Issue #21092: Merge from 3.4.
msg233849 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2015-01-11 13:28
Sorry; that last commit message should have been for #21902.
Date User Action Args
2022-04-11 14:58:00adminsetgithub: 65291
2015-01-11 13:28:15mark.dickinsonsetnosy: + mark.dickinson
messages: + msg233849
2015-01-11 13:23:42python-devsetnosy: + python-dev
messages: + msg233847
2014-03-29 13:39:11brett.cannonsetstatus: open -> closed
resolution: not a bug
2014-03-29 13:34:14berker.peksagsetnosy: + berker.peksag
messages: + msg215129
2014-03-29 02:02:12cvrebertcreate