title: KnockoutJS mappings, JSON from WebAPI
body: <p>I am able to bind JSON returned from .net WebAPI to a knockout viewmodel using the following code.  </p>
  
  <pre><code>function viewModel() {
      var self = this;
      self.temps = ko.observableArray([]);
  }
  
  $(function () { 
      var model = new viewModel();
  
      $.get('../api/Temp/', function (data) { 
          model.temps(data);
      });
  
      ko.applyBindings(model);       
  
  });
  </code></pre>
  
  <p>When  I try to use <a href="http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html" rel="nofollow">Ryan Niemeyer 's mapping example</a> I am getting null when using <code>ko.utils.parseJson</code> on my returned Json and when I try to use the <code>ko.utils.arrayMap</code> directly I am getting undefined.</p>
  
  <p>I am also struggling to take the get request into a separate function if I try the following, my data binding stops working</p>
  
  <pre><code>function dataFromServer() {
      $.get('../api/Temp/', function (data) { 
          return data;
      });
  }
  
  $(function () { 
      var model = new viewModel();
      var data = dataFromServer();
      model.temps(data);
  
      ko.applyBindings(model);       
  
  });
  </code></pre>
  
  <p>Returned JSON from server :</p>
  
  <pre><code>[{"Id":1,"Name":"Test1","TypeId":100,"Temp":21.0,"Peak":true},{"Id":2,"Name":"Test2","TypeId":100,"Temp":21.0,"Peak":true},{"Id":3,"Name":"Test3","TypeId":101,"Temp":21.0,"Peak":true}]
  </code></pre>