In my attempt to transform an existing object into a new object structure, I am facing some challenges.
Here is the current data set:
const jsonStructure = {
"a11/a22/animations": "snimations",
"a11/a22/colours": "sl/colours",
"a11/a22/fonts": "sbal/fonts",
"a11/a22/visibility": "sisibility",
"a11/b22/logo": "sages/logo",
"a11/c22/define": "sst/define",
"a11/c22/ordered": "st/ordered",
"a11/c22/unordered": "sunordered",
"a11/d22/foot": "smeta/foot",
"a11/d22/head": "smeta/head",
"a11/e22/blockquote": "slockquote",
"a11/e22/headings": "s/headings",
"a11/e22/hr": "ss/e/hr",
"a11/e22/inline-elements": "s-elements",
"a11/e22/paragraph": "sparagraph",
"a11/e22/preformatted": "sformatted",
"a11/e22/time": "stext/time",
"b11/f22/menu": "smenu/menu",
"b11/g22/product-item": "sduct-item",
"b11/h22/search": "sch/search",
"b11/i22/sub-menu": "s/sub-menu",
"c11/j22/footer": "ser/footer",
"c11/j22/title": "ster/title",
"c11/k22/header": "ser/header"
};
The desired data structure should look like this:
{
"a11": {
"a22": {
"animations": {
"value": "snimations"
},
"colours": {
"value": "sl/colours"
}
},
"b22": {
"logo":{
"value": "sbal/fonts"
}
}
"c22": {
"define":{
"value": "sst/define"
},
"ordered":{
"value": "st/ordered"
}
}
},
"b11": {
"f22": {
"menu": {
"value": "smenu/menu"
}
},
}
}
I am struggling with structuring the code properly and creating the object in the desired format. My attempts so far have not been successful.
const structure = {
a: {},
b: {},
c: {}
};
let a11 = [];
let b11 = [];
let c11 = [];
for (var hbp in jsonStructure) {
if (hbp.includes("a11")) {
}
if (hbp.includes("b11")) {
}
if (hbp.includes("c11")) {
}
}