title: What is the best way to convert JSON to TypeScript Object?
body: <p>I've <code>JSON</code> string </p>
  
  <p><code>const json = '{ "first_name": "John", "last_name": "Doe"}';</code></p>
  
  <p>and a class <code>User</code></p>
  
  <pre><code>class User {
  
    constructor(
      public first_name: string,
      public last_name: string
    ) {
    }
  
    public getFullName = (): string =&gt; {
      return this.first_name + ' ' + this.last_name;
    };
  }
  </code></pre>
  
  <p>and when I try this</p>
  
  <pre><code>const user: User = JSON.parse(json);
  
  console.log(user.first_name); // Works, prints "John"
  console.log(user.last_name); // Works, prints "Doe"
  console.log(user.getFullName()); //Error: TypeError: user.getFullName is not a function
  </code></pre>
  
  <p>I know the error happened, because <code>JSON.parse</code> simply matched the <code>User</code> type but not methods in it.</p>
  
  <p>So to fix this, I wrote a <code>fromJSON</code> static method in <code>User</code> class to parse manually,</p>
  
  <pre><code>public static fromJSON = (json: string): User =&gt; {
      const jsonObject = JSON.parse(json);
      return new User(
        jsonObject.first_name,
        jsonObject.last_name
      );
  };
  </code></pre>
  
  <p>So these are my questions</p>
  
  <ol>
  <li>Is this a perfect solution ?</li>
  <li>Is there any better solution than this ?</li>
  <li>Is there any built-in solution for this in <code>TypeScript</code>?</li>
  </ol>