I am reading a string from a file and want to convert it into a json object
File content: {name:"sda"}
Code:
var fs=require('fs');
var dir='./folder/';
fs.readdir(dir,function(err,files){
if (err) throw err;
files.forEach(function(file){
fs.readFile(dir+file,'utf-8',function(err,jsonData){
if (err) throw err;
var content=jsonData;
var data=JSON.stringify(content);
console.log(data);
});
});
But I am getting this output: {name:\"sda\"}