saving data

This commit is contained in:
metacryst
2025-11-23 23:24:26 -06:00
parent 8c7ed68975
commit 9d62dbad86
6 changed files with 388 additions and 4 deletions

37
db/processJSON.js Normal file
View File

@@ -0,0 +1,37 @@
import fs from "fs/promises";
import path from "path";
async function processJSON() {
// 1. Read original JSON
const inputPath = path.join(process.cwd(), "db/tokens.json");
const raw = await fs.readFile(inputPath, "utf8");
const data = JSON.parse(raw);
// 2. Create a new result object
const result = {};
// 3. Loop through all entries and modify as needed
const entries = Object.entries(data);
for (const [i, [key, value]] of entries.entries()) {
console.log(i);
// ==== CHANGE THINGS HERE ====
const newValue = {
"labels": value.labels,
"index": i+1,
"url": value.url,
"used": false
};
// =============================
// 4. Put modified entry into result
result[key] = newValue;
}
// 5. Write output JSON
const outputPath = path.join(process.cwd(), "db/output.json");
const jsonString = JSON.stringify(result, null, 2);
await fs.writeFile(outputPath, jsonString, "utf8");
}
processJSON();