If you'd like to access the elements of myfamily
, you can refer to those as myfamily['child1']
, and that will return:
{
"name" : "Emil",
"year" : 2004
}
If child1
was its own directory, you were refer to elements in that as child1['name']
or child1['year']
. Extending that to myfamily['child1']
, you can access elements in child1
by identifying the element you want, like myfamily['child1']['name']
or myfamily['child1']['year']
.
Why doesn't myfamily[child1['name']]
work? If we separate our pieces, child1['name']
contains Emil
. Substitute that for child1['name']
in myfamily[child1['name']]
, and we have myfamily['Emil']
. That element doesn't exist in the myfamily
dictionary, and will fail.