https://github.com/oprogramador/read-json-lines-sync
Synchronous reader of a string containing many lines in JSON format
https://github.com/oprogramador/read-json-lines-sync
Last synced: 10 months ago
JSON representation
Synchronous reader of a string containing many lines in JSON format
- Host: GitHub
- URL: https://github.com/oprogramador/read-json-lines-sync
- Owner: oprogramador
- Created: 2018-06-21T20:35:06.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-08-23T09:09:45.000Z (10 months ago)
- Last Synced: 2025-08-24T03:29:08.288Z (10 months ago)
- Language: JavaScript
- Size: 264 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# read-json-lines-sync
[](https://opensource.org/licenses/MIT)
[](https://travis-ci.com/oprogramador/read-json-lines-sync
)
[](https://npmjs.org/package/read-json-lines-sync
)
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
```js
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).