JSON.unflatten = function(data) {
if (Object(data) !== data || Array.isArray(data))
cur = cur[prop] || (cur[prop] = (x === 0 ? [] : {}));
prop = m[0].substring(0, x);
m[0] = m[0].substring(x);
prop = m[0].substring(1, y);
m[0] = m[0].substring(y + 1);
JSON.flatten = function(data) {
function recurse (cur, prop) {
if (Object(cur) !== cur) {
} else if (Array.isArray(cur)) {
for(var i=0, l=cur.length; i<l; i++)
recurse(cur[i], prop + "[" + i + "]");
recurse(cur[p], prop ? prop+"."+p : p);
for(var x=0; x<tries; x++) {
for(var i=0; i<count; i++) {
temp = JSON.parse(JSON.stringify(fillObj({}, 4)));
time = Date.now() - time;
result.push("Nested : " + noOpt.length + " : " + time);
for(var i=0; i<count; i++) {
temp = JSON.parse(JSON.stringify(fillObj({}, 4)));
temp = JSON.flatten(temp);
temp = JSON.unflatten(temp);
time = Date.now() - time;
result.push("Flattened : " + noOpt.length + " : " + time);
alert(result.join("\n"));
function fillObj(obj, depth) {
obj["foo3"] = 10002525.10002525;
obj["foo4"] = "hello world hello world hello world hello world";
obj["bar4"] = [1,2,3,4,5,6,7,8,9,0];
fillObj(obj["foo5"], depth-1);
obj["bar5"] = [{},{},{},{},{}];
for(var i=0; i<obj["bar5"].length; i++) {
fillObj(obj["bar5"][i], depth-1);
function touchObj(obj, noOpt) {
for(var i=0; i<obj.length; i++) {
} else if(typeof obj === "object" && obj !== null) {