title: How to handle missing JSON data when creating objects? (Typescript)
body: <p>I am retrieving data from the Google Places API and casting it directly into objects for use elsewhere. </p>
  
  <p>The problem is that sometimes the responses do not have all of the fields, so this causes my app to crash when the objects can't properly be created due to missing fields in the JSON response. </p>
  
  <p>Here is an example of what I am talking about:</p>
  
  <p>say the format of a response for example is this:</p>
  
  <pre><code>{ "a" : "some_str", "b" : "some_str", "c" : "some_str" }
  </code></pre>
  
  <p>but once in a while field "b" will be missing, so the response looks like this:</p>
  
  <pre><code>{ "a" : "some_str", "c" : "some_str" }
  </code></pre>
  
  <p>How can I account for this when I try to parse the JSON data into objects?</p>
  
  <p>For example, here is a code that I would use to parse the data:</p>
  
  <pre><code>this.http.get(URL).subscribe(details =&gt; {
      let detailsObj = details.json();
      let myObj: SomeObject = {
          "fieldA" : detailsObj.a,
          "fieldB" : detailsObj.b,
          "fieldC" : detailsObj.c,
      }
  });
  </code></pre>
  
  <p>If the field "b" doesn't exist on the JSON response, the value will be undefined on the "detailsObj" which causes a runtime error as it is trying to create an object with an undefined field.</p>
  
  <p>How can I still create the object despite the partially undefined data? Ideally the data that is missing could be filled with a null.</p>
  
  <p>Any pointers in the right direction would be greatly appreciated, thank you for your time!</p>