How to get the total depth of an unknown JSON hierarchy?
You can use a recursive function to go through the whole tree: getDepth = function (obj) { var depth = 0; if (obj.children) { obj.children.forEach(function (d) { var tmpDepth = getDepth(d) if (tmpDepth > depth) { depth = tmpDepth } }) } return 1 + depth } The function works as follow: If the object … Read more