Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/max-mapper/ndjson
streaming line delimited json parser + serializer
https://github.com/max-mapper/ndjson
Last synced: about 2 months ago
JSON representation
streaming line delimited json parser + serializer
- Host: GitHub
- URL: https://github.com/max-mapper/ndjson
- Owner: max-mapper
- Created: 2013-08-30T21:14:45.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-01-04T01:49:24.000Z (almost 3 years ago)
- Last Synced: 2024-07-31T02:19:56.388Z (5 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 296
- Watchers: 7
- Forks: 37
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Development on this npm package is moved to https://github.com/ndjson/ndjson.js
# 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