Get Depth of a JSON Data

by Sasikumar 2014-08-08 10:20:37

To get depth of JSON data use the following function
Javascript Function :
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.
890
like
0
dislike
0
mail
flag

You must LOGIN to add comments