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.JSONEncoder.default should be called for dict keys as well
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
Status: closed Resolution: duplicate
Dependencies: Superseder: json.dump() ignores its 'default' option when serializing dictionary keys
View: 18820
Assigned To: Nosy List: david.byrne222, kj
Priority: normal Keywords:

Created on 2020-08-17 17:42 by david.byrne222, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (1)
msg375561 - (view) Author: David Byrne (david.byrne222) Date: 2020-08-17 17:42
Sub-classing and overriding json.JSONEncoder.default allows users to create custom serialisation for objects that can’t otherwise be serialized. However, this method is only called for dictionary values such that dictionary supported keys (i.e. hashable types) can not be fully utilized. Calling .default on keys as well as values allows users to to fully utilize json for all dict supported types. 

See for example
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85741
2021-12-30 01:13:58andrei.avksetstatus: open -> closed

nosy: + kj
resolution: duplicate
superseder: json.dump() ignores its 'default' option when serializing dictionary keys
stage: resolved
2020-08-17 17:42:21david.byrne222create