title: d3.nest() to convert csv to json
body: <p>I want to create a nested json file from a csv using d3.nest() however, I am having trouble getting the nesting right. My output looks like this:
  <a href="https://i.stack.imgur.com/TxzLz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TxzLz.png" alt="enter image description here"></a></p>
  
  <p>Which is close but not quite- I would like the values to be 
  key
  values: 
      0: etc
      1: etc</p>
  
  <p>Here is my code: </p>
  
  <p>d3.csv("data/fifa-matches.csv", function(error, matchesCSV) {</p>
  
  <pre><code>    //Loads in the tree information from fifa-tree.csv and calls createTree(csvData) to render the tree.
      matchesCSV.forEach(function(d, i) {
  
          this.teamData = d3.nest()
              .key(function(d) {
                  return d.Team;
              })
  
          .rollup(function(d) {
                  return {
                      Result: { 'Label': d.Result, 'Rank': 'test' },
  
                      // total: d3.sum(v, function(d) { return d.amount; }),
                      // avg: d3.mean(v, function(d) { return d.amount; })
                  }
              })
              .entries(matchesCSV);
          console.log(this.teamData);
      });
  
      d3.csv("data/fifa-tree.csv", function(error, treeCSV) {
  
          //Create a unique "id" field for each game
          treeCSV.forEach(function(d, i) {
              //console.log(d);
              d.id = d.Team + d.Opponent + i;
              d.type = d.Type;
  
  
          });
  </code></pre>
  
  <p>Any info in the right direction would be greatly appreciated!</p>
  
  <p>Here is an example of the structure of the csv:</p>
  
  <p>Team,Opponent,Goals Made,Goals Conceded,Delta Goals,Wins,Losses,Result
  Brazil,Germany,1,7,-6,0,1,Semi Finals
  Germany,Argentina,1,0,1,1,0,Winner
  Argentina,Netherlands,0,0,0,1,0,Semi Finals
  Netherlands,Brazil,3,0,3,1,0,Fourth Place
  Brazil,Colombia,2,1,1,1,0,Quarter Finals
  France,Germany,0,1,-1,0,1,Quarter Finals</p>