1.0.1 • Published 8 years ago

txt-csv-to-json v1.0.1

Weekly downloads
29
License
ISC
Repository
-
Last release
8 years ago

Relational Data to JSON

A node module to read relational data from any ASCII text data file, mainly in (.txt) or (.csv) extension, and to convert the data in to JSON format. Inputs are ascii text data file path and a Regular Expression as column separator. The last parameter of the module is the returned function handle, that can be invocked to fetch the returned JSON data. If specified file is not present the returned function handle will contain Error in JSON format instead of the actual data.

Input 1 - Required - text data file path

Each line/record must end with a newline character.
The very first record will be considered as header row
Per record, fields should be separated by a special character like TAB or Comma

Input 2 - Optional - Field separator

It should be specified as Regular Expression 
Default value is Comma(,) i.e.    /[,](?! )/
Any character can be speficed including TAB chnaracter

This module will transform each record (starting from the second record) into a JSON document using first record's fields as Key.

Installation

npm install txt-csv-to-json

Usage

var textToJson = require('txt-csv-to-json');

textToJson.txtCsvToJson("<.txt or .csv file with path>",[Regular Expression as Field Separator],function(data,err){
    if(data)
        console.log(data);
    if(err)
        console.log(err);
})

Tests

not specified

Contributing