Sequence NODE_223
EasyRead & Write JSON File
Node.js
Technical Specification
Read a JSON file, update a field, and write it back to disk.
Input/Output Samples
Input:config.json with {"visits": 1}
Output:Updated to {"visits": 2}
Optimal Logic Path
const fs = require("fs");
const data = JSON.parse(fs.readFileSync("config.json", "utf8"));
data.visits = (data.visits || 0) + 1;
fs.writeFileSync("config.json", JSON.stringify(data, null, 2));Architectural Deep-Dive
We read JSON as text, parse to object, modify it, then stringify and write back.