Skip to content

Instantly share code, notes, and snippets.

@yawboakye
Created May 28, 2013 14:16
Show Gist options
  • Save yawboakye/5663065 to your computer and use it in GitHub Desktop.
Save yawboakye/5663065 to your computer and use it in GitHub Desktop.
Tiny recursive JSON traversal tool
// simple json traversal tool. *needs improvement*
var json = function (data, padding) {
var p = '';
if ( Object.prototype.toString.call(data) !== '[object Object]' ) {
for ( var i = 0; i < padding; ++i ) p += ' ';
console.log(p + data)
return
} else {
for ( var prop in data ) {
json(data[prop], padding + 2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment