I am scraping data from a URL
containing a csv
. The format of the data I'm scraping is like this:
I am doing this in Node.js
and using the nodejs-requestify package
: https://www.npmjs.com/package/requestify
When I console the response.getBody()
it's in the exact same format as the screenshot provided.
I am trying to convert this to a JSON array
that I can iterate over in a loop to insert the values into a database, however, am struggling to get the data into JSON
format.
I've tried splitting the array in multiple ways (comma, single quote, double quote
). I've tried JSON.parse()
and JSON.stringify()
(and both in combination).
Here is the code I'm using. Ultimately when I console.log
rows in the loop, this is where it should be in JSON
format, however, it's just coming in as comma separated values still.
requestify.get('URL').then(function(response) {
// Get the response body
var dataBody = response.getBody();
var lineArray = dataBody.split('\r\n');
var data = JSON.parse(JSON.stringify(lineArray));
for(var s = 0; s < data.length; s++) {
var rows = data[s];
console.log(rows)
}
});