I'm trying to convert json file to CSV format. In the example https://www.npmjs.com/package/json2csv
const { parse } = require('json2csv');
const fields = ['field1', 'field2', 'field3'];
const opts = { fields };
try {
const csv = parse(myData, opts);
console.log(csv);
} catch (err) {
console.error(err);
}
I don't understand what to do with myData, I tried that:
const { parse } = require('json2csv');
const mydata = require("./mydata.json");
const fields = ['id', 'name'];
const opts = { fields };
try {
const csv = parse(mydata , opts);
console.log(csv);
} catch (err) {
console.error(err);
}
But I don't see the value of mydata, I only get the value which is id and name.
I think it's not going to the child level, which I can see the data