I have some json like this;
example.json
{
"id": 1,
"name": "John Doe",
"age": 23,
"country": "US",
"language": "en",
"created_at": 1534774253,
"updated_at": 1534774269
}
And I have a user.ts interface like this;
user.ts
interface user {
id: number;
name: string;
age: number;
country: string
}
So, how can I cast this json to an object implemented from this interface? I tried const userObj: user = JSON.parse(exampleJson);
but userObj has all the properties in json. I want to generate a user object that has just user.ts properties.
For example => JSON.stringify(userObj);
, the output is {"id":1,"name":"John Doe","age":23,"country":"US"}
.
Anyone knows a way?