read-json-lines-sync

2.2.5 • Public • Published

read-json-lines-sync

MIT License Build Status

NPM status

Synchronous reader of a string containing many lines in JSON format

installation

with NPM:

npm install --save read-json-lines-sync

or with yarn:

yarn add read-json-lines-sync

usage

import readJsonLines from 'read-json-lines-sync';
// or alternative syntax:
// const readJsonLines = require('read-json-lines-sync').default;

const lines = `{"foo":"bar"}
{"foo2":"bar2"}
`;

const result = readJsonLines(lines);

expect(result).to.deep.equal([
  { foo: 'bar' },
  { foo2: 'bar2' },
]);

specification

  • It omits every line which isn't a valid JSON.
  • For the remaining lines, it converts every line into an object.
  • So it always returns an array (possibly an empty array if there's no line with a valid JSON).

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.2.5
    43
    • latest

Version History

Package Sidebar

Install

npm i read-json-lines-sync

Weekly Downloads

71

Version

2.2.5

License

MIT

Unpacked Size

3.51 kB

Total Files

4

Last publish

Collaborators

  • oprogramador