title: How to convert a CSV file into a JSON script using Node.js?
body: <p>test.csv file has:</p>
  
  <pre><code>"Id","UserName","Age"
  "01","Sam Smith","33"
  "02","Fred Frankly","44"
  "03","Zachary Zupers","55"
  </code></pre>
  
  <p>acpected output: as Json File</p>
  
  <pre><code>[{"id":01,"User Name": " Sam Smith", "Age":"33"},
  {"id":03,"User Name": " Fred Frankly", "Age":"44"}
  {"id":03,"User Name": "Aachary Zupers", "Age":"55"}
  ]
  </code></pre>
  
  <p>I tried to solve like this using node.js</p>
  
  <pre><code>var fs = require("fs");
  
  var data = fs.readFileSync('test.csv');
  var stringData=data.toString();
  
  console.log(stringData);
  var arrayOne= stringData.split('\r\n');
  
  var header=arrayOne[0].split(',');
  var noOfRow=arrayOne.length;
  var noOfCol=header.length;
  
  var jArray=[];
  
  var i=0,j=0;
  for (i = 1; i &lt; noOfRow-1; i++) {
  
      for (j = 0; j&lt; noOfCol; j++) {
  
          var myNewLine=arrayOne[i].split(',');
          jArray.push( '{'+header[j]+':'+myNewLine[j]+'}');               
      };
  };
  
  console.log( jArray);
  </code></pre>
  
  <p>this is the output I got when I run the above code:
  <a href="http://i.stack.imgur.com/1XfzT.png" rel="nofollow">output Image</a>
  In the above code I have just tried to show in json script. But If you can do that. Please provide the code to convert the displayed output into a .json file.</p>
  
  <p>Please help me I shall be thankful to you.</p>