This is my text file:
2|BATH BENCH|19.00
20312100000|ORANGE BELL|1.42
04525514840|BOILER ONION|1.78
20422500000|AVOCADO|0.98
My job is the extract the barcode which is 2,20312100000, 04525514840, 2042250000 and convert into a json array which should look like: ["2","20312100000","04525514840","20422500000"]
The code I have is this:
var FilePath = process.argv[2];
var allUpcs = [];
const fs = require('fs');
const readline = require('readline');
const file = readline.createInterface({
input: fs.createReadStream(FilePath),
output: process.stdout,
terminal: false
});
file.on('line', (line) => {
allUpcs.push(line.split('|')[0]);
});
file.on('close', function() {
// console.log(allUpcs.map(Number));
// console.log(JSON.stringify(allUpcs));
console.log(JSON.stringify(allUpcs));
});
I am getting output as this:
[“2”,“20312100000",“04525514840”,“20422500000"]
I need to convert it into json array, can anyone please help thank you.
question from:
https://stackoverflow.com/questions/65893885/coverting-into-json-array 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…