Algorithm · Mongodb · Easy
You are given a JSON object root and a string query_key. Your task is to search through the entire JSON hierarchy (objects and arrays) and retrieve the value corresponding to the key query_key. JSON values may be primitives (like strings, numbers, booleans, or null), objects, or arrays. Arrays can contain any JSON values, including nested objects and arrays. It is guaranteed that query_key occurs exactly once anywhere in the structure. If the found value is an object or an…