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

20 Replies, 1262 Views

The error’s annoying, but it’s not json.dumps’ fault—JSON itself doesn’t support custom types.

If you’re lazy (like me), try `json.dumps(your_obj, default=vars)`. Works if your object’s attributes are simple.

For more control, yeah, you’ll need a custom encoder. Or just use `pickle` if it’s for internal stuff (but don’t use pickle for APIs, obvs).

Messages In This Thread



Users browsing this thread: 2 Guest(s)