27 lines
752 B
JavaScript
27 lines
752 B
JavaScript
import fs from 'fs'
|
|
import {parse} from 'csv-parse'
|
|
|
|
const csvFilePath = './tokens.csv';
|
|
const jsonFilePath = './tokens.json';
|
|
|
|
fs.readFile(csvFilePath, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error('Error reading file:', err);
|
|
return;
|
|
}
|
|
|
|
parse(data, { columns: true, skip_empty_lines: true }, (err, output) => {
|
|
if (err) {
|
|
console.error('Error parsing CSV:', err);
|
|
return;
|
|
}
|
|
|
|
fs.writeFile(jsonFilePath, JSON.stringify(output, null, 2), (err) => {
|
|
if (err) {
|
|
console.error('Error writing JSON file:', err);
|
|
} else {
|
|
console.log(`JSON successfully written to ${jsonFilePath}`);
|
|
}
|
|
});
|
|
});
|
|
}); |