This question evaluates proficiency with JSON data structures, hierarchical traversal, and serialization, testing competency in handling nested objects and arrays, primitive values, and edge cases such as deep nesting and empty containers.
You are given an input JSON object that may contain nested objects and arrays. Your task is to flatten it into a single-level key/value mapping, then serialize that mapping into an output string.
.
to separate nested object keys.
[i]
to represent array indices.
key=value
pairs joined by newlines; pick one and document it).
Input JSON:
{
"a": 1,
"b": {
"c": 2,
"d": [3, 4]
},
"e": [{"f": 5}]
}
One valid flattened result (as a flat JSON object) would be:
{
"a": 1,
"b.c": 2,
"b.d[0]": 3,
"b.d[1]": 4,
"e[0].f": 5
}