Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

txt-file-to-json

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

txt-file-to-json

Reads a txt file having a table and returns an array of obects. In which each object consists of all headers as keys and there data as values.

  • 3.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Reads a text file or data variable having a table and returns an array of obects. In which each object consists of all headers as keys and there data as values.

Installation

npm i --save txt-file-to-json

Usage

txt-file-to-json support CommonJS.

In module system

Use filePath key to provide TEXT data from file.

const txtToJson = require("txt-file-to-json");
const dataInJSON = txtToJSON({ filePath: "./filePath.txt" });

Use data key to provide TEXT data from variable or directly.

const txtToJSON = require("txt-file-to-json");
const dataInJSON = txtToJSON({ data: someTEXTData });

Sample input (txt data) :
FIRST_NAME     LAST_NAME        NUMBER               EMAIL                        ADDRESS
Debra          Burks            880012XXXX           debra.burks@yahoo.com        9273 Thome Ave., `Orchard Park`, NY - 14127
Kasha          Todd             null                 kasha.todd@yahoo.com         910, Vine Street!!!, (Campbell), CA - 95008
Tameka         Fisher           880111XXXX           null                         7693 ~ Honey Creek St., Redondo Beach, "CA"      90278
Sample output (json data) :
[
  {
    FIRST_NAME: 'Debra',
    LAST_NAME: 'Burks',
    NUMBER: '880012XXXX',
    EMAIL: 'debra.burks@yahoo.com',
    ADDRESS: '9273 Thome Ave., `Orchard Park`, NY - 14127'
  },
  {
    FIRST_NAME: 'Kasha',
    LAST_NAME: 'Todd',
    NUMBER: null,
    EMAIL: 'kasha.todd@yahoo.com',
    ADDRESS: '910, Vine Street!!!, (Campbell), CA - 95008'
  },
  {
    FIRST_NAME: 'Tameka',
    LAST_NAME: 'Fisher',
    NUMBER: '880111XXXX',
    EMAIL: null,
    ADDRESS: '7693 ~ Honey Creek St., Redondo Beach, "CA"      90278'
  }
]

Use noOfRecords key along with filePath or data key to get data of specific number of rows.

const txtToJson = require("txt-file-to-json");
const dataInJSON = txtToJSON({ filePath: "./filePath.txt", noOfRecords: 1 });

Sample output when noOfRecords is 1 (json data) :
[
  {
    FIRST_NAME: 'Debra',
    LAST_NAME: 'Burks',
    NUMBER: '880012XXXX',
    EMAIL: 'debra.burks@yahoo.com',
    ADDRESS: '9273 Thome Ave., `Orchard Park`, NY - 14127'
  }
]

References

  • To convert text and csv both to json. Try - https://www.npmjs.com/package/data-to-json
  • To convert only csv data to json. Try - https://www.npmjs.com/package/csv-file-to-json

Keywords

FAQs

Package last updated on 27 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc