38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
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();
|