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 bob.ippolito
Recipients andrewchap, bob.ippolito, rhettinger
Date 2018-10-31.18:19:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541009987.36.0.788709270274.issue35111@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-10-31 18:19:47bob.ippolitosetrecipients: + bob.ippolito, rhettinger, andrewchap
2018-10-31 18:19:47bob.ippolitosetmessageid: <1541009987.36.0.788709270274.issue35111@psf.upfronthosting.co.za>
2018-10-31 18:19:47bob.ippolitolinkissue35111 messages
2018-10-31 18:19:47bob.ippolitocreate