Bob Ippolito <b...@redivi.com> added the comment:

The trouble with having such a hook is that it would take precedence over any 
customization you might want or need to do to satisfy the protocol you're 
implementing. Other than the limited set of types that are part of the JSON 
specification, there's essentially no standard for encoding of anything else. 
This is why customization is left to the call sites for encoding and decoding, 
and I would recommend using the `default` and `object_pairs_hook` keyword 
arguments to `dumps` and `loads` respectively for that, rather than any of the 
options that you've enumerated.

For what it's worth, simplejson has had a `for_json` method hook for several 
years to encourage some consolidation, but it's opt-in and there hasn't been a 
lot of demand to make it the default. The inverse `from_json` type operation is 
not supported. If you think about it, how *could* you even implement such a 
thing in the general case, in a way that wouldn't have lots of surprises and 
performance issues?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35111>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to