title: How to use promises to denormalize nested json?
body: <p>I'm attempting to flatten and denormalize the data. I'm not understanding how to accomplish this using promises. What am I missing?</p>
  
  <p>The result I'm getting is:</p>
  
  <pre><code>Bob,Nancy
  Bob,Nancy
  </code></pre>
  
  <p>But I want to get:</p>
  
  <pre><code>Bob,Sue
  Bob,Nancy
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>var Promise = require('bluebird');
  
  var jsonData = {
    "Parents": [{
      "Name": "Bob",
      "AllChildren": [{
        "Name": "Sue"
      }, {
        "Name": "Nancy"
      }]
    }, {
      "Name": "Ron",
      "AllChildren": [{
        "Name": "Betty"
      }, {
        "Name": "Paula"
      }]
    }, {
      "Name": "Peter",
      "AllChildren": [{
        "Name": "Mary"
      }, {
        "Name": "Sally"
      }]
    }]
  };
  
  
  var promises = Promise.map(jsonData.Parents, function(parent) {
    var record = {};
    record.ParentName = parent.Name;
    var allRecords = Promise.map(parent.AllChildren, function(child) {
      var fullRecord = record;
      fullRecord.ChildName = child.Name;
      return fullRecord;
    });
    return Promise.all(allRecords);
  });
  
  console.log(JSON.stringify(promises, null, 2));
  </code></pre>