title: Angular2 Mapping nested json array to model
body: <p>I am not able to map the nested json array  which is response from Web to my model array in Angular2. Suppose I have json array response as below:</p>
  
  <pre><code>[{
      "base_url": "http://mysearch.net:8080/",
      "date": "2016-11-09",
      "lname": "MY PROJ",
      "name": "HELLO",
      "description": "The Test Project",
      "id": 10886789,
      "creationDate": null,
      "version": "2.9",
      "metrics": [{
          "val": 11926.0,
          "frmt_val": "11,926",
          "key": "lines"
      },
      {
          "val": 7893.0,
          "frmt_val": "7,893",
          "key": "ncloc"
      }],
      "key": "FFDFGDGDG"
  }]
  </code></pre>
  
  <p>I was trying to manually map the fields referring the link <a href="https://stackoverflow.com/questions/36150709/angular-2-observable-doesnt-map-to-model/40947270#40947270">Angular 2 observable doesn&#39;t &#39;map&#39; to model</a> to my model and was able to display those in my HTML by iterating through ngFor.....but I want to also display ncloc and lines value also in the HTML but I am not sure how to map those values to my Model array like mentioned in the above link.
  Can you please help me with this?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Mode class</p>
  
  <pre><code>export class DeiInstance { 
      base_url: string;
      date: string;
      lname : string;
      name : string;
      id : number;
      key:string;
  
      constructor(obj: DeiInstance) {
          this.sonar_url = obj['base_url'];
          this.lname = obj['lname'];
          this.name = obj['name'];
          this.id = obj['id'];
          this.key = obj['key'];
          this.date = obj['date'];
      } 
  
      // New static method. 
      static fromJSONArray(array: Array&lt;DeiInstance&gt;): DeiInstance[] {
          return array.map(obj =&gt; new DeiInstance(obj));
      } 
   } 
  </code></pre>