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

That's what the for_json method is in simplejson, it does not have widespread 
usage.

You can implement that when encoding:

```
def json_default(obj):
    try:
        return obj.__json__()
    except AttributeError:
        raise TypeError("{} can not be JSON encoded".format(type(obj)))


json.dumps(foo(), default=json_default)
```

This way, you can choose precisely how the output needs to work when encoding. 
It's not ideal for every use case, but nothing is. The point is that it doesn't 
get in your way, whatever you need to do can be done without any awful tricks, 
so long as you have control over the dumps call site.

----------

_______________________________________
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