The MongoDB Senior Software Engineer phone screen asked me to implement a deep key search over a nested JSON object. Values associated with keys could have different types, including strings, lists, and additional nested JSON objects.
Given a query key, the function needed to search through the JSON structure recursively and return the value associated with that key, even when the matching key appeared several levels below the root.
Interview Details
Coding — Search for a Key Anywhere in Nested JSON The input is a JSON object whose values may be primitive values, lists, or additional nested objects. For example: