<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div class="h5"><br>
</div></div>You&#39;re correct, this is trivial with object_hook.<br>
<div class="im"><br>
&gt;&gt;&gt; class AttrDict(dict):<br>
...     def __getattr__(self, attr):<br>
</div>...         try:<br>
...             return self[attr]<br>
...         except KeyError:<br>
...             raise AttributeError(attr)<br>
...<br>
&gt;&gt;&gt; import json<br>
&gt;&gt;&gt; obj = json.loads(&#39;{&quot;foo&quot;: {&quot;bar&quot;: &quot;baz&quot;}}&#39;, object_hook=AttrDict)<br>
{u&#39;foo&#39;: {u&#39;bar&#39;: u&#39;baz&#39;}}<br>
&gt;&gt;&gt; obj.foo.bar<br>
u&#39;baz&#39;<br>
<font color="#888888"><br>
-bob<br>
</font></blockquote></div><br><div>That&#39;s pretty good, but it does clone the dict unnecessarily. I prefer:</div><div><br></div><div>class AttrDict(object):</div><div>  def __init__(self, adict):</div><div>    self.__dict__ = adict #a reference, not a copy</div>

<div>  def __getattr__(self, attr):</div><div>    if hasattr(dict, attr): #built-in methods of dict...</div><div>      return getattr(self.__dict__, attr) #...are bound directly to the dict</div><div>    else:</div><div>
      try:</div>
<div>        return self.__dict__[attr]</div><div>      except KeyError:</div><div>        raise AttributeError(attr)</div><div><br></div><div><br></div><div>          </div><div><br></div>