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