Javascript JSON go to inner key by an index : I have a JSON like this:

     var json = {
        a : "xxxx",
        b : {
            p : 12,
            a : "xxxx",
            b : {
                r : 1,
                a : "xxxx",
                b : null
            }
        }
    }

and i want a function that passing in as parameters a key, an index and an object, add this last object to the json at the inner level indicated by the index.<br>
I know, I have not explained well, an example:

    

    function addObjectToJSON(key,index,object){
        var helpJSON = json;
        for(var i = 0; i < index; i++){
            helpJSON = helpJSON[key];
        }
        helpJSON = object;     
        
    }

the above function obviously does not work.

i want that the result of this: 

    addObjectToJSON("b",2,{ a: 2, b: null});

was:

    var json = {
        a : "xxxx",
        b : {
            p : 12,
            a : "xxxx",
            b : {
                r : 1,
                a : "xxxx",
                b : {
                     a : 2,
                     b : null   
                }
            }
        }
    }

