Sha256: 4ac8946a540eba21a5faa7c1f293e06663932636dfb480d120affcc7de7c9a5a

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# ndjson

streaming [newline delimited json](https://en.wikipedia.org/wiki/Line_Delimited_JSON) parser + serializer. Available as a JS API or a command line tool

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

## usage

```
var ndjson = require('ndjson')
```

#### ndjson.parse(opts)

returns a transform stream that accepts newline delimited json and emits objects

example newline delimited json:

`data.txt`:

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

If you want to discard non-valid JSON messages, you can call `ndjson.parse({strict: false})`

usage:

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

#### ndjson.serialize() / ndjson.stringify()

returns a transform stream that accepts json objects and emits newline delimited json

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()
```

### license

BSD-3-Clause

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
node_task-0.3.5 lib/node_task/node_modules/ndjson/readme.md
node_task-0.3.4 lib/node_task/node_modules/ndjson/readme.md
node_task-0.3.3 lib/node_task/node_modules/ndjson/readme.md
node_task-0.3.2 lib/node_task/node_modules/ndjson/readme.md
node_task-0.3.1 lib/node_task/node_modules/ndjson/readme.md
node_task-0.3.0 lib/node_task/node_modules/ndjson/readme.md
node_task-0.2.0 lib/node_task/node_modules/ndjson/readme.md