Convert .txt file to JSON
You can try to use tsv2json this tool can reads a tsv file from stdin and writes a json file to stdout.
It's distributed in source file, to compile it you need to download D compiler and then run dmd tsv2json.d
.
If you have more complex task there is another tool named tsv-utils
TSV to JSON in nodejs
var file_name = 'city_list.txt';var readline = require('readline');var fs = require('fs');var lineReader = readline.createInterface({ input: fs.createReadStream(file_name)});var isHeader = false;var columnNames = [];function parseLine(line) { return line.trim().split('\t')}function createRowObject(values) { var rowObject = {}; columnNames.forEach((value,index) => { rowObject[value] = values[index]; }); return rowObject;}var json = {};json[file_name] = [];lineReader.on('line', function (line) { if(!isHeader) { columnNames = parseLine(line); isHeader = true; } else { json[file_name].push(createRowObject(parseLine(line))); }});lineReader.on('close', function () { fs.writeFileSync(file_name + '.json', JSON.stringify(json,null,2));});