I am trying to parse a JSON file with the code below, but I am getting an error:
var fs = require('fs');
var sampleData = require("./sampleData.json");
var dataInArray = JSON.parse(sampleData.toString());
Here is the error:
$ node prog.js
undefined:1
[object Object]
^
SyntaxError: Unexpected token o
at Object.parse (native)
at Object.<anonymous> (~/prog.js:3:24) //The line where I perform the JSON parsing
What am I doing wrong?