title: How to make a class JSON serializable
body: <p>How to make a Python class serializable?</p>
  <pre><code>class FileItem:
      def __init__(self, fname):
          self.fname = fname
  </code></pre>
  <p>Attempt to serialize to JSON:</p>
  <pre><code>&gt;&gt;&gt; import json
  &gt;&gt;&gt; x = FileItem('/foo/bar')
  &gt;&gt;&gt; json.dumps(x)
  TypeError: Object of type 'FileItem' is not JSON serializable
  </code></pre>