title: Serializing class instance to JSON
body: <p>I am trying to create a JSON string representation of a class instance and having difficulty. Let's say the class is built like this:</p>
  
  <pre><code>class testclass:
      value1 = "a"
      value2 = "b"
  </code></pre>
  
  <p>A call to the json.dumps is made like this:</p>
  
  <pre><code>t = testclass()
  json.dumps(t)
  </code></pre>
  
  <p>It is failing and telling me that the testclass is not JSON serializable.</p>
  
  <pre><code>TypeError: &lt;__main__.testclass object at 0x000000000227A400&gt; is not JSON serializable
  </code></pre>
  
  <p>I have also tried using the pickle module :</p>
  
  <pre><code>t = testclass()
  print(pickle.dumps(t, pickle.HIGHEST_PROTOCOL))
  </code></pre>
  
  <p>And it gives class instance information but not a serialized content of the class instance.</p>
  
  <pre><code>b'\x80\x03c__main__\ntestclass\nq\x00)\x81q\x01}q\x02b.'
  </code></pre>
  
  <p>What am I doing wrong?</p>