Problem Β· Hash Table
Dynamic Path Accessor
Learn this problemProblem statement
Implement get_dict_value for a nested dictionary and a dot-separated path. Each path segment names a key in the current dictionary.
- If every segment exists, return the value at that path.
- If a segment is missing, or an intermediate value is not a dictionary, return
None.
The runner provides the following parameters:
String objJson: a JSON serialization of the source dictionaryString path: the dot-separated path to access
Return: A string containing the resolved value as compact JSON text, or None when the path does not exist.
Function
get_dict_value(objJson: String, path: String) β StringExamples
Example 1
objJson = "{\"car\":{\"wheels\":2,\"gears\":5}}"path = "car.gears"return = "5"The path car.gears resolves to the integer 5. The runner returns its compact JSON representation, 5.