3

I have an array of object like this

I want to write this code into a file such that I can dump into my db.

data =  [{"test":"1"},{"test":"2"}]
function writeFinalData (data) {
  var toWriteListXml = config.exportPath + 'data.json',
  toWriteData = data.toString();
  fs.writeFile(toWriteListXml, toWriteData, function (err) {
    if (err) {
      return console.log(err);
    }
    console.log("The file was saved!");
  });
}

With this code ,I can see in my file as

[Object Object],[Object Object]

Can anyone please help me to write my data as it is like an array.
Thanks in advance.

Rajesh Patel
  • 1,946
  • 16
  • 20
Duster
  • 99
  • 3
  • 9

0 Answers0