jsonlines
Parse [JSONLines](http://jsonlines.org) with Node.js.
Last updated 9 years ago by linusu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jsonlines 
SYNC missed versions from official npm registry.

JSONLines for Node.js

Parse JSONLines with Node.js.

Installation

npm install --save jsonlines

Usage

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

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:

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

Current Tags

  • 0.1.1                                ...           latest (9 years ago)

2 Versions

  • 0.1.1                                ...           9 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |