title: How to Convert an array of Nested JSON Objects into CSV in NodeJS and ExpressJS
body: <p>I want to send the CSV file from Server to Client.
  I have JSON Objects which I am getting from MongoDB with ExpressJS Response.</p>
  
  <p>Here is my Code for NodeJS Which is Accepting a Post Request from Client with Id's in the Body and with a Collection Name Parameter, and in Response, it fetches the data related to those Ids.</p>
  
  <pre><code>app.post('/api/v1/imagelist_data/raw-data/:db', function(req, res) {
      console.log("I received a NEW POST raw-data request");
      var dbname = req.params.db;
  
      var myarray = req.body._id;
  
      //  Setting Collection Name
      var mycollection = db.collection(dbname);
  
      // Convert the list of ids to mongo object ids
      var objectIds = myarray.map(function(item) {
          return mongojs.ObjectId(item);
      });
  
      console.log(objectIds);
  
      mycollection.find({
          _id: {
              $in: objectIds
          }
      }, function(err, docs) {
  
          res.json(docs);
  
  
      });
  </code></pre>
  
  <p>Now am getting the Array of Objects in Response at the Client Side.
  I want to make a CSV File with these Array of Objects.</p>
  
  <p>Arrays of Objects looks like this.</p>
  
  <pre><code>[
  {
      "_id": "58405524d70210dc299ca275",
      "pictureNumber": 1,
      "scAttitude": [
          0,
          0,
          0,
          1
      ],
      "scPosition": [
          1,
          0,
          0
      ],
      "integrationTime": 10,
      "time": "2016-12-01T16:51:57.000Z",
      "offset": 1,
      "gain": 2,
      "ledStatus": false,
      "imageType": "Image",
      "cameraType": "Mongo",
      "testPatternStatus": false,
      "temperatureCCD": 189,
      "temperatureLED1": 162,
      "temperatureLED2": 152,
      "temperatureVBG": 490,
      "temperatureGND": 0,
      "imageValid": true,
      "remarks": " Reception time: Thu Dec 01 17:51:47 CET 2016",
      "imageSize": 2271320
  },
  {
      "_id": "586bc534b31a89bb45b0083e",
      "pictureNumber": 2,
      "scAttitude": [
          1,
          0,
          0,
          1
      ],
      "scPosition": [
          1,
          0,
          0
      ],
      "integrationTime": 20,
      "time": "2016-12-02T16:51:57.000Z",
      "offset": 2,
      "gain": 0,
      "ledStatus": false,
      "imageType": "Image",
      "cameraType": "MOngo",
      "testPatternStatus": false,
      "temperatureCCD": 189,
      "temperatureLED1": 162,
      "temperatureLED2": 152,
      "temperatureVBG": 490,
      "temperatureGND": 0,
      "imageValid": true,
      "remarks": " Reception time: Thu Dec 01 17:51:47 CET 2016",
      "imageSize": 2271320
  }]
  </code></pre>
  
  <p>Should I do this Processing at the Server Side or Client Side?</p>
  
  <p>I want to download the CSV file with the data at the client side with the click of the button.</p>
  
  <p>How can I achieve this?</p>