function getDepthOfJson (obj) { var depth = 0; if (obj.children) { obj.children.forEach(function (d) { var tmpDepth = getDepth(d) if (tmpDepth > depth) { depth = tmpDepth } }) } return 1 + depth }This helps in finding the depth of a json data. Call this function by passing the json object as argument.