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

20 Replies, 1193 Views

json.dumps is like that one teacher who only accepts homework in *exactly* the right format.

For a dirty workaround, just `print(vars(your_obj))` and copy-paste into a dict. Not scalable, but gets you unstuck.

For a real solution, yeah, custom encoder or a lib like `simplejson` (handles more types out of the box).

Messages In This Thread



Users browsing this thread: 1 Guest(s)