Many APIs return JSON that is converted into a multilevel dictionary (e.g. EPO OPS). The following code snippet helps find a key (e.g. “id”) that is nested within the dictionary.
The function is based on this answer. To find more than the first occurrence “return” may be converted to “yield”.
"""Recursive function to look for first occurrence of key in multi-level dict.
param string key: key to locate"""