Accessing JavaScript Sub-properties by Name
<p>I wrote the following JavaScript function (part of a larger "class") to help ensure anybody using the object stores attribute values in the "values" property.</p>

<pre><code>function _updateAttributes(attribute, value) {
    _attributes[attribute] = { values: { value: value }};
}
</code></pre>

<p>It works fine for a flat structure, but falls apart when I start trying to use it for sub-properties.</p>

<p>After running the following code:</p>

<pre><code>myEntity.updateAttribute('name', 'Frankenstein');
myEntity.updateAttribute('name.source', 'John Doe');
</code></pre>

<p>I'd like the following structure:</p>

<pre><code>{
    "attributes": {
        "name": {
            "values": {
                "value": "Frankenstein"
            },
            "source": {
                "values": {
                    "value": "JohnDoe"
                }
            }
        }
    }
}
</code></pre>

<p>Instead, it's coming out like this:</p>

<pre><code>{
    "attributes": {
        "name": {
            "values": {
                "value": "Frankenstein"
            }
        },
        "name.source": {
            "values": {
                "value": "JohnDoe"
            }
        }
    }
}
</code></pre>

<p>Is there any clean way to write this JavaScript or will I be faced with splitting out the strings and manually building the structure?</p>

<p><strong>NOTE:</strong> I realize even the preferred structure is a little odd, but there's a Java object I'm mapping to that expects this format, so I don't have any options here.</p>
