1.0.0 • Published 6 years ago

txt-to-json v1.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

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]
})