[docs] [issue18820] json.dump() ignores its 'default' option when serializing dictionary keys

Erwin Mayer report at bugs.python.org
Fri Apr 8 08:41:34 EDT 2016


Erwin Mayer added the comment:

Regarding the issues mentioned in https://github.com/simplejson/simplejson/issues/77, they already apply with the current implementation anyway (true is serialized as 'true'), so users must already be careful.

The JSONEncoder with default parameters could definitely keep rejecting complex keys, but an optional 'encode_complex_keys=False' parameter could be added to __init__ to provide this functionality. There would be zero performance impact as the parameter check would only be done if all else has failed instead of raising the TypeError (the same way _skipkeys does).

In that respect, the patch of this issue would need to be amended (and the C version would also need to be changed).

I am trying to fork the json core module to achieve this (to not have to wait for the next Python release, assuming it gets implemented), if you are familiar with the packaging process of core modules into standalone modules, your advice would be much appreciated (and could well help others contribute to Python):
http://stackoverflow.com/questions/36498527/how-to-create-a-customized-version-of-a-core-python-module-that-includes-c-code

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18820>
_______________________________________


More information about the docs mailing list