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.

Author serhiy.storchaka
Recipients Daniel Ward, Ollie Ford, abarry, berker.peksag, bob.ippolito, r.david.murray, rhettinger, serhiy.storchaka, steven.daprano
Date 2017-03-05.10:03:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This feature already was proposed for simplejson ( Special __json__ method is used in wild in a number of projects for exactly this purpose. It looks to me the main disagreement in the past Python-Idea discussion ( was about whether implement the customization as a special method or as a registry. I suggest to implement both. Special methods are good for standard collection and numeric classes, global registry is good for application-wide serialization, local dispatch table or the default method are good for more specific task-specific customization.

Here is a draft implementation. It follows the design of pickle and copy modules.

There are few design questions.

1. What is the order of using different customization methods? Should registries and __json__ be checked before calling the default method, after calling the default method (if it fails), or inside the default implementation of the default method?

2. For Decimal we need to customize raw JSON representation. In the past it was possible to implement an intermediate float or int subclass with __str__ or __repr__ returning raw JSON representation. But this hack no longer works. Needed to add explicit support of special JSON representation objects. Other way -- add yet one special method (__raw_json__ or __json_str__).

3. Do we need the json.registry() function for global registration, or it is enough to expose the json.dispatch_table mapping?
Date User Action Args
2017-03-05 10:03:59serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, bob.ippolito, steven.daprano, r.david.murray, berker.peksag, abarry, Daniel Ward, Ollie Ford
2017-03-05 10:03:59serhiy.storchakasetmessageid: <>
2017-03-05 10:03:59serhiy.storchakalinkissue27362 messages
2017-03-05 10:03:56serhiy.storchakacreate