I would use the knockout mapping plugin.
var jsonData = {
id : 1,
details: {
name: "Johnny",
surname: "Boy"
}
}
var yourMapping = {
'details': {
create: function(options) {
return Details(options.data);
}
}
}
function Details(data) {
ko.mapping.fromJS(data, {}, this);
}
function YourObjectName() {
ko.mapping.fromJS(jsonData, yourMapping, this);
}
This will create your object hierarchy with all of the children as observables.