New submission from Daniel Ward:

To help prevent retrospective JSONEncoder overrides when failing to serialize a 
given object, the intention of this issue is to propose that the JSON encoder 
checks if a given object has a __json__ attribute, using that rather than 
raising a TypeError.

This will help in maintaining easier-to-follow code and keeps the 
responsibility of determining how an object should be represented in JSON 
objects firmly within the object itself.

The obj.__json__ callable/attribute should behave in the same way as __repr__ 
or __str__, for example.

I'm happy to look in to contributing this enhancement myself if that's 
preferred. Any pointers as to how I go about contributing are greatly 
appreciated.

----------
components: Library (Lib)
messages: 268991
nosy: Daniel Ward
priority: normal
severity: normal
status: open
title: json.dumps to check for obj.__json__ before raising TypeError
type: enhancement

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

Reply via email to