function str2json(str) { var arr = str.split('.'), json = {}, _this = json; if (!json[arr[0]]) json[arr[0]] = {}; for (var i = 0, len = arr.length; i < len; i++) if (_this[arr[i]]) _this = _this[arr[i]]; else _this = _this[arr[i]] = {}; return json; } alert(str2json('damai.search.history'));