When I try to use json.dumps
on an object of a class that uses __slots__
, I get "...is not JSON serializable," or possibly an AttributeError
that __dict__
is missing. How can I get this to work? It seems that __slots__
should tell the interpreter to use a virtual dictionary for compatibility.
import json
class Foo:
__slots__ = ["bar"]
def __init__(self):
self.bar = 0
json.dumps(Foo())