#C14827. Nested Dictionary Flattening
Nested Dictionary Flattening
Nested Dictionary Flattening
You are given a JSON object representing a nested dictionary. Your task is to flatten the dictionary. In the flattened dictionary, the keys from nested objects are concatenated into a single key using a dot (.) as the separator. For example, given the input {"a":1,"b":{"c":2,"d":3}}
, the output should be {"a":1,"b.c":2,"b.d":3}
.
If a nested dictionary is empty, it should be ignored. The flattened dictionary should only include keys with non-dictionary values.
The relation for concatenated keys can be formalized as follows:
\( key_{flat} = parentKey \; \text{if} \; parentKey = \emptyset \; \text{else} \; parentKey + '.' + key \)
inputFormat
The input is provided via standard input in a single line. It contains a valid JSON string representing a nested dictionary. The keys are strings without spaces while the values are either integers or nested dictionaries.
outputFormat
The output should be a JSON string representing the flattened dictionary. The keys must be a concatenation of nested keys separated by a dot (.) without any extra spaces.
## sample{"a":1,"b":2,"c":3}
{"a":1,"b":2,"c":3}