#K54282. Flatten Nested JSON
Flatten Nested JSON
Flatten Nested JSON
You are given a JSON string representing a nested dictionary. Your task is to flatten the JSON by converting all nested keys into a single level using dot-separated paths. For example, given a nested key structure, you should output a flat dictionary where each key is a concatenation of the nested keys separated by a dot.
More formally, if you have a JSON object, each key in the output should be in the following format:
\( key_{1}.key_{2}.\ldots.key_{n} \)
where the keys are determined by the depth-first traversal of the nested dictionary. The values remain unchanged from the original JSON.
Note: An empty JSON object should return an empty JSON object.
inputFormat
The input consists of a single JSON string read from standard input (stdin). The JSON string represents a nested dictionary. It is guaranteed to be a valid JSON.
Example Input:
{"a":1, "b":{"c":2, "d":3}}
outputFormat
The output should be the flattened dictionary printed as a JSON string to standard output (stdout). The keys in the output JSON should be the dot-separated paths corresponding to the original nested keys.
Example Output:
{"a":1,"b.c":2,"b.d":3}## sample
{"a":1,"b":{"c":2,"d":{"e":3,"f":4}}}
{"a":1,"b.c":2,"b.d.e":3,"b.d.f":4}