#K11186. Flatten Nested JSON Object
Flatten Nested JSON Object
Flatten Nested JSON Object
Given a JSON object which may contain nested objects, your task is to flatten it. In the flattened version, any keys nested inside another object are concatenated with their parent keys using the dot symbol as a separator. More formally, if a key \( k \) inside an object contained in key \( p \) exists, then in the flattened JSON it appears as p.k
.
For example, if the input is:
{ "a": 1, "b": { "c": 2 } }
Then the output should be:
{ "a": 1, "b.c": 2 }
Make sure to use the separator as . and output the flattened JSON in valid JSON format.
inputFormat
The input is provided as a single line from stdin
containing a valid JSON object. The object may have nested JSON objects.
outputFormat
Output to stdout
a single line containing the flattened JSON object in valid JSON format. The keys from nested objects should be concatenated with their parent keys, separated by a dot .
.
{"a":1,"b":{"c":2}}
{"a":1,"b.c":2}