I am looking for a solution to convert a JSON into a TypeScript object. Here is an example of the JSON data:
{
"key1": {
"a": "b"
},
"key2": {
"a": "c"
}
}
The keys key1
and key2
are unknown, so I cannot directly create an interface for them. However, the objects associated with these keys are always the same.
Currently, I have defined my object as follows:
export interface MyObj {
a: string;
}
But how can I convert the JSON into an object? I attempted to use a map object type like this:
export interface AllMyObj {
valKey: Map<string, MyObj>;
}
However, I am unsure what should be used in place of valKey
.