I have a class Person and after setting its properties, figuring out best way to convert that class to json object.
class Person {
firstName: string;
lastName: string;
}
let person = new Person();
person.firstName = "FirstName";
person.lastName = "LastName";
If i do person.getJson() it should give json object as given below
{
"firstName": "FirstName",
"lastName": "LastName"
}
and incase lastName is not set then json object should only have firstName
{
"firstName": "FirstName"
}