saving data
This commit is contained in:
37
db/processJSON.js
Normal file
37
db/processJSON.js
Normal 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();
|
||||
Reference in New Issue
Block a user