updating a deep key in a Nested JSON file
<p>I have a json file which looks like this:</p>

<pre><code>{
    "email": "abctest@xxx.com", 
    "firstName": "name01", 
    "surname": "Optional"
    "layer01": {
        "key1": "value1", 
        "key2": "value2", 
        "key3": "value3", 
        "key4": "value4", 
        "layer02": {
            "key1": "value1", 
            "key2": "value2"
        }, 
        "layer03": [
            {
                "inner_key01": "inner value01"
            }, 
            {
                "inner_key02": "inner_value02"
            }
        ]
    }, 
    "surname": "Required only$uid"
}
</code></pre>

<p>am expecting a update request as:</p>

<pre><code>{
                "email": "XYZTEST@gmail.com",
                "firstName": "firstName",
                "layer01.key3": "newvalue03",
                "layer01.layer02.key1": "newvalue01"
            },
</code></pre>

<p>the deeper keys are separated using <code>"."</code></p>

<p>am using python2.7. Can anyone advice me on this.. am really stuck at this!!</p>

<p>this is what i was working with:</p>

<pre><code>def updateTemplate(self,templatename, data):
    template= self.getTemplatedata(templatename) # gets the python object with the data from original file

    for ref in data:
        k= ref
        keys= ref.split(".")
        temp= template
        if len(keys)&gt;1:
            temp= template[keys[0]]
            for i in range(1,lens(keys)-1):
                print keys[i]
                if type(temp) is dict:
                    temp =temp[keys[i]]



            temp[keys[len(keys)-1]]= data[k]
            print temp

            template.update(temp)        
        else:
            template[k]= data[k]   
    print template  
</code></pre>

<p>update added a whole new key in the template object. I need to update the key in last temp to template object </p>

<p>the template object displayed this:</p>

<pre><code>{   u'email': u'abctest@xxx.com',
    u'firstName': u'Valid AU$uid',
    u'key1': u'value1',
    u'key2': u'value2',
    u'key3': u'value03',
    u'key4': u'value4',
    u'layer01': {   u'key1': u'value1',
                    u'key2': u'value2',
                    u'key3': u'value03',
                    u'key4': u'value4',
                    u'layer02': {   u'key1': u'value01', u'key2': u'value2'},
                    u'layer03': [   {   u'inner_key01': u'inner value01'},
                                    {   u'inner_key02': u'inner_value02'}]},
    u'layer02': {   u'key1': u'value01', u'key2': u'value2'},
    u'layer03': [   {   u'inner_key01': u'inner value01'},
                    {   u'inner_key02': u'inner_value02'}],
    u'surname': u'Required only$uid'}
</code></pre>