Q:

Django json nested list .get()

I am stuck with a silly problem.
I have a json data and trying to save it in my model.
Here is the code.
response = response.json() #this gives json data
response = json.loads(response) #loads string to json           
json_string = response #ready to get data from list
modelfielda = json_string.get("abc") # this works fine
modelfieldb = json_string.get('["c"]["d"]["e"]') #this does not give data though data is present.

My json data comes like this:
{  
   "abc":"AP003",
   "c":[  
      {  
         "d":{  
            "e":"some data",
            "f":"some data"
         }
      }
   ]
}

So my question is how to get data inside c.

A:

By using multiple .gets:
bnm = json_string.get('c')[0].get('d').get('e')  # bnm = 'some data'

Or perhaps better (since it will error in case the key does not exists):
bnm = json_string['c'][0]['d']['e']  # bnm = 'some data'

Since you converted it to a Python dictionary, you basically work with a dictionary, and you can obtain the value corresponding to a key by using some_dict[some_key]. Since we here have a cascade of dictionaries, we thus obtain the subdictionary for which we again obtain the corresponding value. The value corresponding to c is a list, and we can obtain the first element by writing [0].

