title: IndexedDB and Javascript: JSON and objects misunderstanding
body: <p>I'm trying to obtain information from a JSON file download to the client through AJAX and I'm getting different results depending on the JSON format and I don't know how to fix the one with problem.</p>
  
  <p>First case: </p>
  
  <p>The json files looks like:</p>
  
  <pre><code>    [{"name": "nick",
      "age": 28},
      {"name": "katie",
      "age": 32}]
  </code></pre>
  
  <p>My AJAX .done method looks like:</p>
  
  <pre><code>    .done(
      function(data) { 
          addObjectsDB (data, "people");
      })
  </code></pre>
  
  <p>This method calls a second one that iterates through data and stored correctly each object into IndexedDB.</p>
  
  <p>Second case:
  Now I have a JSON file with different format:</p>
  
  <pre><code>    [
      {
       "husband": {
        "name": "Jhon",
        "age": 23 },
       "wife": {
        "name": "Marie",
        "age": 24 }
       }
       ]
  </code></pre>
  
  <p>Now my .done() AJAX method iterates through data and add each person, husband or wife to an array which is then sent to the DB with the same method than the first case:</p>
  
  <pre><code>    .done(
      function(data) { 
          var people = [];
          $(data).each(function (key, value){
              people.push(value.husband);
              people.push(value.wife);                
          });
          addObjectsDB (people, "people");
      })
  </code></pre>
  
  <p>In this case the insertion into the database fails, if for example, instead of adding value.husband to people array I just add value to people array the insertion works, but I need each person stored separated in the DB.</p>
  
  <p>The addObjectsDB method is:</p>
  
  <pre><code>    function addObjectsDB (data, collection) {
          var objectStore = db.transaction(collection, "readwrite").objectStore(collection);
          $.each (data, function (key, value) {
              var request = objectStore.add(value);
          });
      }
  </code></pre>
  
  <p>As I said the first case works perfectly but the second one inserts nothing and no error is showed...</p>
  
  <p>I think the problem is that I don't understand javascript types adequately but I'm starting with it and I've spent a whole evening with it.</p>