i have a function that scans a directory and builds a key,value pair of all folders and their respective files in it.
const listNotes = () => {
const listing = [];
try{
const folders = fs.readdirSync(defaultPath);
folders.forEach((folder) => {
let v = fs.readdirSync(`${defaultPath}/${folder}`);
listing[folder] = v;
});
} catch (err) {
console.log(err);
}
return listing;
};
and this is an output of such scan
[ DailyTask: [ 'Chores.json' , 'Sunday.json'] ]
that is a folder called DailyTask containing 2 files.
How do i convert this structure to JSON.