Skip to content

Instantly share code, notes, and snippets.

@ginpei
Created November 21, 2011 18:46
Show Gist options
  • Save ginpei/1383512 to your computer and use it in GitHub Desktop.
Save ginpei/1383512 to your computer and use it in GitHub Desktop.
parse object like JSON
/*
var s = parseObject(data);
console.log(s);
*/
function parseObject(data) {
function f(data, indent, result) {
for (var p in data) {
var s = indent + p + ':';
if (typeof data[p] != 'object') {
result[result.length] = s + data[p];
}
else {
result[result.length] = s;
f(data[p], indent+' ', result);
}
}
return result;
}
return f(data, '', []).join('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment