var obj = {
"database.host": "127.0.0.1",
"database.user": "test",
"database.password": "qwerty",
"rest.photo.host": "127.0.0.2",
"rest.users.host": "127.0.0.3",
"rest.users.password": "p@ssw0rd",
"baseUrl": "test.com",
"limit": 10
};
var result = {};
Object.keys(obj).forEach(function (name) {
var path = result, names = name.split("."), len = names.length;
names.forEach(function (subName, index) {
if (!path[subName]) {
if (index == len - 1) {
path[subName] = obj[name];
} else {
path[subName] = {};
}
}
path = path[subName];
});
});
alert(JSON.stringify(result , "", 4));