Safely reads a JSON file.
(filePath)
| 90 | |
| 91 | /** Safely reads a JSON file. */ |
| 92 | function loadJson(filePath) { |
| 93 | if (!fs.existsSync(filePath)) return {}; |
| 94 | try { |
| 95 | return JSON.parse(fs.readFileSync(filePath, 'utf8')); |
| 96 | } catch (error) { |
| 97 | console.error(`Error parsing JSON file ${filePath}:`, error.message); |
| 98 | return {}; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /** Writes a JSON file with standardized formatting. */ |
| 103 | function saveJson(filePath, data) { |
no test coverage detected