title: Prepare JSON data on basis of JSON and array - JavaScript
body: <p>I have a JSON file with the following structure:</p>
  
  <pre><code>{ ShippingDate: '06.09.2016',
      'Order ID': 200003946,
      ID: 751,
      Product: 'Mobile Phone'},
    { ShippingDate: '06.09.2016',
      'Order ID': 200003946,
      ID: 751,
      Product: 'TV'},
    { ShippingDate: '06.09.2016',
      'Order ID': 200003946,
      ID: 751,
      Product: 'Batteries'},
    { ShippingDate: '06.09.2016',
      'Order ID': 200003926,
      ID: 752,
      Product: 'Car'},
  </code></pre>
  
  <p>So the first three entries are an order of the same customer. The fourth one is an order of another customer.</p>
  
  <p>I know want to use a handlebars.js template to create an html file with each order including the items the order has. So I prepared this template:</p>
  
  <pre><code>&lt;div class="header"&gt;
      &lt;h1&gt;{{ID}}&lt;/h1&gt;
  &lt;/div&gt;
  &lt;div class="body"&gt;
      &lt;ul&gt;
        {{#each Product}}
          &lt;li&gt;{{this}}&lt;/li&gt;
        {{/each}}
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I now have the problem, that I need to prepare that kind of data for the template. And here I stumbled across some problems. My code goes like this</p>
  
  <pre><code>...
  var f = fs.readFileSync('data.json').toString();
  var lines = JSON.parse(f);
  var items = [];
  //prepare products of one customer and put them into an array
  for (var key in lines) {
  
    var line = lines[key];
    var nextLine = lines[(parseInt(key)+1)];
  
    if (nextLine !== undefined &amp;&amp; line !== undefined) {
      if (line['Order ID'] !== nextLine['Order ID']) {
          items.push('Product: ' + line.Product);
      }//if   
    }//if
  }//for
  
  var data = lines;
  fs.readFile(template.html, 'utf-8', function(error, source){
    var template = handlebars.compile(source);
    var html = template(data);
    console.log(html)
  });
  </code></pre>
  
  <p>This is not working - how can I prepare my array of items so that I can access these products with the products variable in my template? Additionally I need to add information like ID and Shipping Date to that json string. The data format must look like this:</p>
  
  <pre><code>var data = {
    ShippingDate: '06.09.2016',
    ID: '751',
    Product: ['Mobile Phone', 'TV', 'Batteries']
  }
  </code></pre>
  
  <p>Anybody can help here?</p>