#C13349. Flatten Nested Dictionary
Flatten Nested Dictionary
Flatten Nested Dictionary
Given a nested dictionary, your task is to flatten it by concatenating keys from each level into a single key using the dot ('.') as a separator. In other words, for a nested key structure, if an inner key is encountered, its new key becomes the concatenation of the parent keys and the child key separated by dots. For example, a nested dictionary like {"a": {"b": 1}}
should be flattened to {"a.b": 1}
.
The transformation follows the formula: $$new_key = parent_key + \. + current_key$$ (if a parent key exists).
If a nested dictionary is empty, do not produce any key for it. Your solution should read input from standard input (stdin) and print the resulting flattened dictionary in JSON format to standard output (stdout).
inputFormat
The input consists of a single line containing a JSON object that represents a nested dictionary. Keys are strings. Values can be integers, strings, null, or nested dictionaries.
outputFormat
Output the flattened dictionary in JSON format to standard output.## sample
{"a": 1, "b": 2}
{"a":1,"b":2}