txt-to-json
v1.0.0
Published
Simple script that reads txt files and outputs their JSON equivalent.
Downloads
2
Readme
txt-to-json
txt-to-json is a simple script that converts txt files to JSON and outputs them in the core working directory. txt-to-json allows for full customization, letting you insert your own filter functions to determine keys and values.
Installation
Install via npm: npm install txt-to-json
Usage
const txtToJson = require('txt-to-json')
txtToJson('./data.txt')
Example input
key1:value1
key2:value2
Example output
{"key1":"value1","key2":"value2"}
Using line and key filters
If your keys are split by commas, and values by hyphens, use:
txtToJson('./data.txt', function (doc) {
return doc.split(',')
}, function (line) {
const [key, value] = line.split('-')
return [key, value]
})