I am looking for a nice solution to access a property by string value, but if the property does not exist it should create it. If the root structure already has defined some
I wouldn't reinvent the wheel in this case, and instead use lodash. Specifically the set() function. As per their example:
var object = { 'a': [{ 'b': { 'c': 3 } }] };
_.set(object, 'a[0].b.c', 4);
console.log(object.a[0].b.c);
// => 4
_.set(object, ['x', '0', 'y', 'z'], 5);
console.log(object.x[0].y.z);
// => 5