#C1163. Flatten a Nested Dictionary
Flatten a Nested Dictionary
Flatten a Nested Dictionary
You are given a nested dictionary in JSON format. Your task is to flatten this dictionary so that any nested key is concatenated with its parent key using a period ('.'). For example, if you are given a dictionary such as
$${\; "a": 1, \; "b": {\; "c": 2, \; "d": {\; "e": 3\; }\; }\; } $$then the flattened dictionary should be:
It is guaranteed that all keys are non-empty strings and values are either integers or dictionaries. There are no arrays in the input. The output must be printed in JSON format with the flattened keys.
inputFormat
The input is read from standard input (stdin) and consists of a single line containing a JSON string that represents a nested dictionary. The dictionary may be empty or contain multiple levels of nested dictionaries.
outputFormat
Print the flattened dictionary in JSON format to standard output (stdout). In the flattened dictionary, keys from different levels are concatenated with a dot ('.') as a separator.## sample
{"a":1}
{"a":1}