I am working with a flat JSON data in TypeScript / JavaScript that needs to be structured hierarchically for creating a questionnaire later on.
Below are my TypeScript classes:
export class Template
{
template_id: number;
template_name: string;
sections: Section[];
}
export class Section
{
section_id: number;
section_name: string;
fields: Field[];
}
export class Field
{
field_id: number;
field_lable : string; //Typo fixed from "field_lable" to "field_label"
input_type: InputType;
}
export class InputType
{
input_type_id: number;
input_type_name: string;
}
Example of flat data. It will eventually be a list of templates
templates: Template[];
[
{
"Template_id":1,
"Template_Name":"Enterprise",
"Section_id":1,
"Section_Name":"Basic Info",
"Field_id":1,
"Field_Label":"Enter Your Name",
"Input_Type_id":1,
"Input_Type_Name":"Text"
},
...
]
I'm interested in knowing if there are any lodash or similar libraries functions I can leverage
Expected Output:
[
{
"Template_id":1,
"Template_Name":"Enterprise",
"Sections":[
{
"Section_id":1,
"Section_Name":"Basic Info",
"Fields":[
{
"Field_id":1,
"Field_Label":"Enter Your Name",
"Input_Type_id":1,
"Input_Type_Name":"Text"
},
...
]
},
...
]
},
...
]