title: convert json string into knockout observable array
body: <p>I am trying to convert a JSON string into a knockout.js observable array. </p>
  
  <p>Here is my js code:</p>
  
  <pre><code>$(document).ready(function(e){
      var model =  function(dat){
          this.tabledata = ko.observableArray(dat);
      };
  
      $.ajax({
          url: 'http://localhost:1141/rest_service/show_data',
          type: 'GET',
          success: function(msg){
              // var dat = JSON.parse(msg);
  
              alert(msg);
              ko.applyBindings(new model(msg));
          },
          error: function(msg){
              alert(JSON.stringify(msg));
          },
      });
  });
  </code></pre>
  
  <p>and here is my html:</p>
  
  <pre><code>&lt;table id = "example" &gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Employee ID&lt;/th&gt;
              &lt;th&gt;Employee Name&lt;/th&gt;
              &lt;th&gt;Employee Status&lt;/th&gt;
              &lt;th&gt;Date of birth&lt;/th&gt;
              &lt;th&gt;Age&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody data-bind='foreach: tabledata'&gt;
         &lt;tr&gt;
             &lt;td data-bind='text: $parent.empId'/&gt;&lt;/td&gt; 
              &lt;td data-bind='text: $parent.empStatus'/&gt;&lt;/td&gt;
              &lt;td data-bind='text:$parent.dob'/&gt;&lt;/td&gt;
              &lt;td data-bind='text: $parent.empName'/&gt;&lt;/td&gt;
              &lt;td data-bind='text: $parent.age'/&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>So here, after an ajax call, I am getting a JSON string as a response from the server and I want to bind this data to html table.</p>
  
  <p>I tried using <code>ko.mapping.fromJs()</code> to convert the incoming JSON to an observable array but received the following error:</p>
  
  <pre><code>Error: The argument passed when initializing an observable array must be an array, or null, or undefined.
  </code></pre>
  
  <p>The JSON response is as follows:</p>
  
  <pre><code>[
   {"empId":100,"empName":"TA","empStatus":"yes","dob":"2000-12-12","age":15},   
   {"empId":101,"empName":"TA","empStatus":"yes","dob":"2000-12-12","age":15},
   {"empId":102,"empName":"TATA","empStatus":"yes","dob":"1997-12-12","age":18},
   {"empId":103,"empName":"kljh","empStatus":"yes","dob":"2000-12-12","age":15},
   {"empId":111,"empName":"Aria","empStatus":"No","dob":"1995-10-17","age":20}
  ]
  </code></pre>
  
  <p>How can I change my code so that the JSON string is converted properly into a Knockout.js observable array?</p>