I have a unique input as shown below:
{
survey.subObject1.key1: true,
survey.subObject1.key2: "OTHER",
survey.subObject2.key3: "[1,2]",
survey.subObject2.key4: false,
survey2.subObject3.key5: false,
survey2.subObject3.key6: false
}
I am looking to convert it into an object structure like this:
{
survey: {
subObject1 : {
key1: true,
key2: "OTHER"
},
subObject2 : {
key3: "[1,2]",
key4: false
}
},
survey2: {
subObject3 : {
key5: false,
key6: false
}
}
}
Currently, I am able to stringify the keys and iterate through them using a for loop, but I am struggling with recreating the object structure afterwards:
const x = {
"survey.subObject1.key1": true,
"survey.subObject1.key2": "OTHER",
"survey.subObject2.key3": "[1,2]",
"survey.subObject2.key4": false,
"survey2.subObject3.key5": false,
"survey2.subObject3.key6": false
}
for (const [key, value] of Object.entries(x)) {
console.log(key)
console.log(value);
}