0.1.0 • Published 5 years ago

node-jsonl v0.1.0

Weekly downloads
1,528
License
MIT
Repository
github
Last release
5 years ago

node-jsonl

NodeJS Iterate over JSONL Line Delimited JSON

Install

Using Yarn:

yarn add node-jsonl

or using NPM:

npm install --save node-jsonl

Import Module

CommonJS

const jsonl = require("node-jsonl");

Typescript (ES6)

import * as jsonl from "node-jsonl";

Quickstart

example.jsonl

{"name":"joe"}
{"name":"bob"}
{"name":"frank"}
{"name":"marie"}

Read JSONL one line at a time

const rl = jsonl.readlines<T>(filepath)

while (true) {
    const {value, done} = await rl.next()
    if (done) break;
    console.log(value); // value => T
}

Read JSONL multiple lines at a time

const rl = jsonl.readlinesChunk<T>(filepath, maxlines)

while (true) {
    const {value, done} = await rl.next()
    if (done) break;
    console.log(value); // value => Array<T>
}