JSFiddle - React, Tailwind, and code Playground

by Ian Sadovy

TypeScript

class Person {
  public firstName: string;
  public lastName: string;

  public toObject(): Object {
    var output: Object = {};
    output["firstName"] = this.firstName;
    output["lastName"] = this.lastName;
    return output;
  }

  public static fromObject(input: Object): Person {
    var output = new Person();
    output.firstName = input["firstName"];
    output.lastName = input["lastName"];
    return output;
  }
}

var json = { 
	firstName: "John",
  lastName: "Doe"
};
var person = Person.fromObject(json);
console.log(person.firstName, person.lastName);

// convert back to JSON
console.log(person.toObject());