Why does json.dumps sometimes fail to serialize my Python object? or How can I customize the output f

20 Replies, 1317 Views

Dude, same. json.dumps is *so* finicky.

Try this hack: `json.dumps(your_obj, default=lambda x: str(x) if hasattr(x, '__str__') else None)`

It’ll at least give you *something* instead of crashing. Not ideal for prod, but great for debugging.

Messages In This Thread



Users browsing this thread: 1 Guest(s)