Skip to content

Instantly share code, notes, and snippets.

@juandaveth
Created February 24, 2019 13:59
Show Gist options
  • Save juandaveth/72f569e4d30ebc21e4ab832b87ab9364 to your computer and use it in GitHub Desktop.
Save juandaveth/72f569e4d30ebc21e4ab832b87ab9364 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const callback = (err, data) => {
try {
const toString = JSON.stringify(data);
const parsed = JSON.parse(toString);
const cleaned = parsed.replace(/“|”/g, "");
const newArray = cleaned.split("\n");
console.log(newArray);
fs.writeFile("./file.json", JSON.stringify(newArray, null, 4), (err) => {
if (err) {
console.error(err);
return;
};
console.log("JSON file was created.");
});
} catch (e) {
console.log(e);
}
};
fs.readFile("./file.txt", "utf8", callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment