Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Created February 24, 2017 07:10
Show Gist options
  • Save rjoydip-zz/c989f41fff8c40c60bd6cdbbeb133da0 to your computer and use it in GitHub Desktop.
Save rjoydip-zz/c989f41fff8c40c60bd6cdbbeb133da0 to your computer and use it in GitHub Desktop.
This function traverse the hole object and checking whether the object value of each layer has a nested object or not
function isObject(obj){
return (typeof obj === 'object') ? true : false;
}
function traverse (json, callback) {
JSON.parse(json, function (key, value) {
if (key !== '') {
callback.call(this, key, isObject(value))
}
return value
})
}
traverse('{"a":{"b":{"c":{"d":1}},"e":{"f":2}}}', function (key, value) {
console.log(key+ " : " +value)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment