# jsonlines

> Parse [JSONLines](http://jsonlines.org) with Node.js.

Latest version **0.1.1** (published 2017-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonlines
pnpm add jsonlines
yarn add jsonlines
bun add jsonlines
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-06-14 |
| First published | 2015-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/jsonlines) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Linus Unnebäck |
| Maintainers | linusu |

## Links

- npm: https://www.npmjs.com/package/jsonlines
- Repository: https://github.com/LinusU/node-jsonlines
- Homepage: https://github.com/LinusU/node-jsonlines#readme
- Issues: https://github.com/LinusU/node-jsonlines/issues
- npm.io page: https://npm.io/package/jsonlines

## Recent versions

- 0.1.1 (latest) — 2017-06-14
- 0.1.0 — 2015-08-10

## README

# JSONLines for Node.js

Parse [JSONLines](http://jsonlines.org) with Node.js.

## Installation

```sh
npm install --save jsonlines
```

## Usage

```javascript
var jsonlines = require('jsonlines')
var parser = jsonlines.parse()

parser.on('data', function (data) {
  console.log('Got json:', data)
})

parser.on('end', function () {
  console.log('No more data')
})

parser.write('{ "test": "This is a test!" }\n')
parser.write('{ "jsonlines": "is awesome" }')
parser.end()
```

```javascript
var jsonlines = require('jsonlines')
var stringifier = jsonlines.stringify()

stringifier.pipe(process.stdout)

stringifier.write({ test: 'This is a test!' })
stringifier.write({ jsonlines: 'is awesome' })
stringifier.end()
```

## API

### `.parse([options])`

Returns a transform stream that turns newline separated json into a stream of
javascript values.

`options` is an optional object with the keys documented below.

### `.stringify()`

Returns a transform stream that turns javascript values into a stream of newline
separated json.

## Options

### `emitInvalidLine`

If true, instead of emitting an error and cancelling the stream when an invalid line is proccessed, an `invalid-line` event is emitted with the same error. This is very useful when processing text that have mixed plain text and json data.

Example:

```js
var jsonlines = require('jsonlines')
var parser = jsonlines.parse({ emitInvalidLines: true })

parser.on('data', function (data) {
  console.log('Got json:', data)
})

parser.on('invalid-line', function (err) {
  console.log('Got text:', err.source)
})

parser.write('{ "test": "This is a test!" }\n')
parser.write('This is some plain text\n')
parser.write('{ "jsonlines": "is awesome" }')
parser.end()
```

Output:

```text
Got json: { test: 'This is a test!' }
Got text: This is some plain text
Got json: { jsonlines: 'is awesome' }
```

---
_Source: https://npm.io/package/jsonlines · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
