It seems if your key is saved in a variable. data.key = value
won't work.
You should use data[key] = value
Example:
data = {key1:'v1', key2:'v2'};
var mykey = 'key1';
data.mykey = 'newv1';
data[mykey] = 'newV2';
console.log(data);
Result:
{
"key1": "newV2",
"key2": "v2",
"mykey": "newv1"
}