# ndjson

> Streaming newline delimited json parser + serializer

Latest version **2.0.0** (published 2020-08-15) · BSD-3-Clause license · 0 weekly downloads

## Install

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

Provides the command `ndjson`.

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-08-15 |
| First published | 2014-09-23 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | separate (@types/ndjson) |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 5 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 136 |
| Author | max ogden |
| Maintainers | contra, finnpauls, maxogden |
| Keywords | ndjson, ldjson |

## Links

- npm: https://www.npmjs.com/package/ndjson
- Repository: https://github.com/ndjson/ndjson.js
- Issues: https://github.com/ndjson/ndjson.js/issues
- npm.io page: https://npm.io/package/ndjson

## Dependencies (5)

- [split2](https://npm.io/package/split2.md) ^3.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.5
- [through2](https://npm.io/package/through2.md) ^4.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^3.6.0
- [json-stringify-safe](https://npm.io/package/json-stringify-safe.md) ^5.0.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-08-15
- 1.5.0 — 2016-12-05
- 1.4.4 — 2016-12-05
- 1.4.3 — 2015-11-01
- 1.4.2 — 2015-09-16
- 1.4.1 — 2015-06-22
- 1.4.0 — 2015-06-22
- 1.3.1 — 2015-06-17
- 1.3.0 — 2014-11-18
- 1.2.3 — 2014-09-30
- 1.2.2 — 2014-09-23
- 1.2.1 — 2014-09-23

## README

# ndjson

Streaming [newline delimited json](https://en.wikipedia.org/wiki/Line_Delimited_JSON) parser + serializer. Available as a JS API and a CLI.

[![NPM](https://nodei.co/npm/ndjson.png)](https://nodei.co/npm/ndjson/)

## Usage

```
const ndjson = require('ndjson')
```

#### ndjson.parse([opts])

Returns a transform stream that accepts newline delimited json buffers and emits objects of parsed data.

Example file:

```
{"foo": "bar"}
{"hello": "world"}
```

Parsing it:

```js
fs.createReadStream('data.txt')
  .pipe(ndjson.parse())
  .on('data', function(obj) {
    // obj is a javascript object
  })
```


##### Options

- `strict` can be set to false to discard non-valid JSON messages
- All other options are passed through to the stream class.

#### ndjson.stringify([opts])

Returns a transform stream that accepts JSON objects and emits newline delimited json buffers.

example usage:

```js
var serialize = ndjson.serialize()
serialize.on('data', function(line) {
  // line is a line of stringified JSON with a newline delimiter at the end
})
serialize.write({"foo": "bar"})
serialize.end()
```

##### Options

Options are passed through to the stream class.

### LICENSE

BSD-3-Clause

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