This question evaluates the ability to traverse and manipulate nested JSON-like structures, emphasizing concepts such as recursion or iterative traversal, array indexing, and path string construction; it tests data structures and serialization knowledge within the Coding & Algorithms domain and targets practical implementation skills for a software engineer role. It is commonly asked to assess how interviewees flatten hierarchical payloads for data processing or API normalization, reason about mixed object/array edge cases, and map hierarchical paths to primitive values.
You are given a JSON-like value representing an object that may contain:
Return a flattened map from path to primitive value.
.
to join object keys.
[i]
for array indices.
Input
{
"a": 1,
"b": {"c": 2, "d": [3, 4]},
"e": [ {"f": 5}, 6 ]
}
Output
a -> 1
b.c -> 2
b.d[0] -> 3
b.d[1] -> 4
e[0].f -> 5
e[1] -> 6
.
and
[
]
(you may assume this to avoid escaping).
string -> primitive
.
Implement a function to perform this flattening.