I am looking for a quick and efficient way to determine the maximum "depth" of a JSON object. For instance, an object like
{
a: "aVal",
b: {
b1: "b1Val",
b2: "b2Val",
b3: {
b3a: "b3aVal"
}
}
}
would have a maximum depth of 2, since there are two nested objects at "b" and "b3".
Is there a lodash solution for this? or a quick javascript function? All I can think of is iterating through using Object.keys() and checking every nested object to determine which is the deepest, but there must be a more optimal solution than that.
Any ideas?