title: Converting an array into JSON
body: <p>I need to bring in a csv doc and convert it to JSON, so far I have been able to convert it to an array and from the array I'm trying to build a JSON object. </p>
  
  <p>Below is the JavaScript that builds the JSON, but its not in the structure I need, underneath is an example of the structure required.</p>
  
  <pre><code>var jsonObj = []; //declare object
  
  for (var i=1;i&lt;csvAsArray.length;i++) { 
    jsonObj.push({key: csvAsArray[i][0]}); //key
  
      for (var l=1;l&lt;csvAsArray[0].length;l++) { 
        jsonObj.push({label: csvAsArray[0][l], values: csvAsArray[i][l]}); //label + value respectively
      }
  }
  </code></pre>
  
  <p>Final output required:</p>
  
  <pre><code>{
    "key": "Sample 01",
    "values": [
      { 
        "label" : "Something" ,
        "value" : 1
      } , 
      { 
        "label" : "Something" ,
        "value" : 2
      }
    ]
  },
  {
    "key": "Sample 02",
    "values": [
      { 
        "label" : "Something" ,
        "value" : 5
      } , 
      { 
        "label" : "Something" ,
        "value" : 4
      }
    ]
  }
  </code></pre>