lila/data-pipeline/utils/write-json-file.ts
2026-07-06 13:09:30 +02:00

11 lines
349 B
TypeScript

import fs from "fs";
/**
* Writes data as formatted JSON to a file path.
* Safely catches and re-throws file system errors.
*/
export function writeJsonFile(filePath: string, data: unknown): void {
const tempPath = `${filePath}.tmp`;
fs.writeFileSync(tempPath, JSON.stringify(data, null, 2), "utf-8");
fs.renameSync(tempPath, filePath);
}