Skip to content

Instantly share code, notes, and snippets.

@chrisparnin
Last active December 19, 2015 23:08
Show Gist options
  • Save chrisparnin/6032323 to your computer and use it in GitHub Desktop.
Save chrisparnin/6032323 to your computer and use it in GitHub Desktop.
Summarize JSON
var sum = function(o, tabLevel){
for(var prop in o){
if(o.hasOwnProperty(prop)){
var val = o[prop];
var header = "";
for( var t = 0; t < tabLevel; t++ )
{
header += '\t';
}
console.log(header + prop + ":");
if(typeof val == 'object'){
sum(val, tabLevel+1);
}
}
}
};
sum({ 'foo':'bar', biz: { x: 'y', nested: { z: [1,2,3,4] } } }, 0);
@chrisparnin
Copy link
Author

Output:

foo:
biz:
    x:
    nested:
        z:
            0:
            1:
            2:
            3:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment