After extensively searching the web, reading through typescript documents, and reviewing numerous responses here on stack overflow, I have yet to find a solution that fully addresses my query:
In my typescript code, I import a JSON
file with the following structure:
[
{
"property" : "FristName",
"type" : "string"
},
{
"property" : "LastName",
"type" : "string"
},
{
"property" : "Age",
"type" : "number"
}
]
The key property
represents a class property
while the key type
indicates the property type
.
My goal is to create a class constructor in such a way that it dynamically generates the following at runtime:
class Person {
public FirstName: string;
public LastName: string;
public Age: number
{
The JSON array
may contain multiple object literals indexed from n
. These object literals are static in structure and will always consist of the two attributes attribute
and type
.