Text File to json is a text to array of objects converter
#Text file to json Currently two methods are available 1.TextFileWithGrid 2.TextFileWithoutGrid
#Installation $ npm install text_file_to_json
#API var text_file_to_json=require("text_file_to_json")
######TextFileWithGrid: It is used to convert from text file in table format to array of objects or json
using the following table to parse data
will produce
[
{
"Date": "20.09.2011",
"Order Quantity": "100",
"Delivered qty": "7"
},
{
"Date": "16.08.2012",
"Order Quantity": "4",
"Delivered qty": "0"
}
]
The syntax for TextFileWithGrid is textFileWithGrid(fileLocation,splitSymbol,headingLineNumber,ignoreLines)
##How to use it?
const text_file_to_json=require("text_file_to_json")
const jsonData=text_file_to_json.textFileWithGrid('./testing.txt',1,'|',[0,1,2])
Note:
- headingLineNumber and ignoreLines are optional
- ignoreLines should be in asscending order by default ignoreLines is [0,1,2,last line of the text file]
- By deafault headingLineNumber is 1
######TextFileWithoutGrid: It is csv to json converter .
using the following txt file data to parse json
Heading1,heading2,heading3,heading4
name1,address1,contact1,status1
name2,address2,contact2,status2
will produce
[
{
"Heading1": "name1",
"heading2": "address1",
"heading3": "contact1"
},
{
"Heading1": "name2",
"Heading2": "address2",
"Heading3": "contact2"
}
]
The syntax for TextFileWithoutGrid is
textFileWithoutGrid(File)
##How to use it? const text_file_to_json=require("text_file_to_json") const jsondata=textFileWithoutGrid('./testing1.txt')