title: How do you enable python's json package to encode attrdict.AttrDict objects?
body: <p>How do you encode AttrDict objects in json?</p>
  
  <pre><code>import sys, json, attrdict
  
  ad = attrdict.AttrDict({'else': 1, 'inner': attrdict.AttrDict({'something': 2})})
  
  json.dump(ad, sys.stdout)
  </code></pre>
  
  <p>This fails with <code>TypeError: a{'something': 2} is not JSON serializable</code></p>
  
  <p>Using a custom encoder like this works but I have to reference the private _mapping property:</p>
  
  <pre><code>import sys, json, attrdict
  
  class attrDictEncoder(json.JSONEncoder):
      def default(self, obj):
          if isinstance(obj, attrdict.AttrDict):
              return obj._mapping
          return json.JSONEncoder.default(self, obj)
  
  ad = attrdict.AttrDict({'else': 1, 'inner': attrdict.AttrDict({'something': 2})})
  
  json.dump(ad, sys.stdout, cls=attrDictEncoder)
  </code></pre>
  
  <p>is there a better/cleaner way? I don't want to have to rebuild the dicts, item by item into a plain dicts.</p>