I have a class
export class User {
constructor(public firstname:string,
public lastname:string
public email:string
public password:string){}
}
I want to send it as a Json but the User data should be a Json object inside another object. The final json should look as follows
{
"external-profile":{
"firstname":"something",
"lastname":"something",
"email":"some@something",
"password":"something"
}
}
How could I do this in Angular? I tried the following two approaches but they don't work
1) creating an object of type User and doing JSON.stringify(user) produces
{
"firstname":"something", <-- not embedded in external-profile
"lastname":"something",
"email":"some@something",
"password":"something"
}
2) creating another class UserProfiles as follows
class UserProfile{
constructor(public externalProfile:User){} //I can't use hypen separated variable names in Typescript it seems.
}
the above produces if I create an object of type UserProfile and JSON.stringify it.
{
"externalProfile":{ <-- I want external-profile, not externalProfile
"firstname":"something",
"lastname":"something",
"email":"some@something",
"password":"something"
}
}