'Safely get nested list index from json?

I know how to safely get keys from json using .get()

data = {"person": {"name": "chris", "age": 11, "interests": []}}

data.get("person", {}).get("height") would just return None

But what if I wanted to do the same with a list?

data.get("person", {}).get("interests", []).get([3], {}).get("someotherdata")

How do I assume the list index exists and carry on safely if it doesn't?

Obviously I could just try getting the list and checking its length before trying to get the index, but is there not a cleaner way?

Chris



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source