I have a json string and I want to know what its maximum depth is. By depth I mean the number of embedded keys. So if one key as 7 "children" and know other key had that many, the depth would be 8.
Since the only types (I believe) that can embed other objects are arrays and other dictionaries that is all that would need to be checked. Is there a way to check this?
I was hoping to achieve this without external modules but if not I am targeting python3.
NOTE: Here is what I mean by "depth"
The following dictionary:
{
"path": "/0001_Anthem",
"name": "0001_Anthem",
"isMovie": true,
"runtime": 3600,
"thumbnailLocation": "/thubs/test.png",
"id": 1,
"media": [
{
"path": "/0001_Anthem/louvers.mp4",
"name": "louvers.mp4"
}
]
}
Would have a "depth" or length of 3 because the farthest embedded item is the key/value pair (level 3) in the media array (level 2), in the main dictionary (level 1). I am not sure what terminology others use, this is just the terminology I think make sense.
Thanks
collections.Mappingandcollections.Sequenceif you say "arrays and dicts"?