Initialize nested classes from JSON in Python?
<p>When writing APIs I often need to initialize classes from nested JSONs like this</p>

<pre><code># When my API receives such a ...
n_json = {"nested1": {"nested2" : { "nested3" : "..." }}}

# .. I need to instantiate a proper object out of it ...
nested1 = Nested1.from_json(json.loads(n_json))

# ... so I can later use the instance in OOP style.
nested1.nested2.run_an_intance_method()
</code></pre>

<p>In my code this results in cascades of</p>

<pre><code>class Nested1:
    @classmethod
    def from_json(json):
        self.nested2=Nested2.from_json(json.nested2)
</code></pre>

<p>With every layer of nesting this gets more repetetive and error prone. Any clever way to do this?</p>