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