title: How can I loop through an array of JSON objects?
body: <p>I have JSON data that I need to loop through. The data is in a file titled "people.json" that is structured as listed below:</p>
  
  <pre><code>[{"firstname":"John","lastname":"Smith","age":"40"},{"firstname":"Bill","lastname":"Jones","age":"40"}, ...]
  </code></pre>
  
  <p>I want to read each object in this file and save it (I'm using Mongoose). Here is what I have so far:</p>
  
  <pre><code>var fs = require('fs');
  var Person = require('../models/people');
  
  fs.readFile('./people.json', 'utf8', function (err,data) {
      var i;
      for(i = 0; i &lt; data.length; i++) {
          var newPerson = new Person();
          newPerson.firstname = data[i].firstname;
          newPerson.lastname = data[i].lastname;
          newPerson.age = data[i].age;
          newPerson.save(function (err) {});
      }
  });
  </code></pre>
  
  <p>I'm unable to get this to work though. What am I doing wrong?</p>