How to convert nested list to object
<p>When I receive JSON data like </p>

<pre><code>[  
    {  
        "id":1,
        "name":"New Island",
        "residents":[  
            {  
                "name":"Paul",
                "age":"25"
            }
        ]
    },
    {  
        "id":2,
        "name":"One Nation",
        "residents":[  
            {  
                "name":"James",
                "age":"23"
            },
            {  
                "name":"Jessica",
                "age":"26"
            }
        ]
    }
]
</code></pre>

<p>drf deserializer makes it to list which contain OrderedDict</p>

<p>But I want to make it to list of class object.</p>

<p>Here are my django models</p>

<pre><code>class Country(models.Model):
    name = models.CharField(max_length=20)

class Resident(models.Model):
    name = models.CharField(max_length=20)
    country = models.ForeignKey('Country', related_name='residents')
</code></pre>

<p>From Python's <a href="https://docs.python.org/3.5/library/json.html" rel="nofollow">JSON library</a></p>

<pre><code>import json

data = '[{"id":1,"name":"New Island","residents":[{"name":"Paul","age":"25"}]},{"id":2,"name":"One Nation","residents":[{"name":"James","age":"23"},{"name":"Jessica","age":"26"}]}]'

x = json.loads(data)

for each_set in x:
    for every_person in each_set["residents"]:
        print(every_person["name"]) #getting resident's name
        print(every_person["age"])  #getting age
        print(each_set["name"]) #getting the country name
</code></pre>

<p>From there it's as easy as passing in the proper parameters to classes like</p>

python django django-rest-framework