I have a couple of JSON files that I generated using a tool. The problem is, even thought this JSONs are valid, they don't have any indentation at all.
I already tried something like this:
fs.readdir(path, function (err, files) {
if (err) {
return console.log('Unable to scan directory: ' + err);
}
files.forEach((file) => {
const pathToFile = `../jsonFiles/${file}`;
fs.readFile(pathToFile, 'utf-8', (err, data) => {
fs.writeFile(pathToFile, JSON.parse(JSON.stringify(data, null, 4)), (err) => {
if (err) {
console.log(err)
}
});
});
});
});