-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfileReader.js.txt
42 lines (35 loc) · 1 KB
/
fileReader.js.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require("fs");
const path = require("path")
// Path to the JSON file
export const data = () => {
const jsonFilePath = path.join(__dirname, "test.json");
// Path to the output JSON file
const outputFilePath = path.join(__dirname, "output.json");
// Read the JSON file
fs.readFile(jsonFilePath, "utf8", (err, data) => {
if (err) {
console.error("Error reading the file:", err);
return;
}
try {
// Parse the JSON data
const jsonData = JSON.parse(data);
return jsonData;
// Write the manipulated data to another file
/*fs.writeFile(
outputFilePath,
JSON.stringify(jsonData, null, 2),
"utf8",
(writeErr) => {
if (writeErr) {
console.error("Error writing the file:", writeErr);
return;
}
console.log("Parsed data has been written to", outputFilePath);
}
);*/
} catch (parseErr) {
console.error("Error parsing JSON:", parseErr);
}
});
};