function parse(opts) {
opts = opts || {}
opts.strict = opts.strict !== false
function parseRow (row) {
try {
if (row) return JSON.parse(row)
} catch (e) {
if (opts.strict) {
this.emit('error', new Error('Could not parse row ' + row.slice(0, 50) + '...'))
}
}
}
return split(parseRow, opts)
}n/a
function parse(opts) {
opts = opts || {}
opts.strict = opts.strict !== false
function parseRow (row) {
try {
if (row) return JSON.parse(row)
} catch (e) {
if (opts.strict) {
this.emit('error', new Error('Could not parse row ' + row.slice(0, 50) + '...'))
}
}
}
return split(parseRow, opts)
}...
console.error('Usage: ndjson [input] <options>')
process.exit(1)
}
if (first === '-') inputStream = process.stdin
else inputStream = fs.createReadStream(first)
var parse = ndjson.parse(args)
var serializer = ndjson.serialize(args)
inputStream.pipe(parse).pipe(serializer).pipe(process.stdout)
...function serialize(opts) {
return through.obj(opts, function(obj, enc, cb) {
cb(null, stringify(obj) + EOL)
})
}...
process.exit(1)
}
if (first === '-') inputStream = process.stdin
else inputStream = fs.createReadStream(first)
var parse = ndjson.parse(args)
var serializer = ndjson.serialize(args)
inputStream.pipe(parse).pipe(serializer).pipe(process.stdout)
...function serialize(opts) {
return through.obj(opts, function(obj, enc, cb) {
cb(null, stringify(obj) + EOL)
})
}...
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()
...function parse(opts) {
opts = opts || {}
opts.strict = opts.strict !== false
function parseRow (row) {
try {
if (row) return JSON.parse(row)
} catch (e) {
if (opts.strict) {
this.emit('error', new Error('Could not parse row ' + row.slice(0, 50) + '...'))
}
}
}
return split(parseRow, opts)
}...
console.error('Usage: ndjson [input] <options>')
process.exit(1)
}
if (first === '-') inputStream = process.stdin
else inputStream = fs.createReadStream(first)
var parse = ndjson.parse(args)
var serializer = ndjson.serialize(args)
inputStream.pipe(parse).pipe(serializer).pipe(process.stdout)
...function serialize(opts) {
return through.obj(opts, function(obj, enc, cb) {
cb(null, stringify(obj) + EOL)
})
}...
process.exit(1)
}
if (first === '-') inputStream = process.stdin
else inputStream = fs.createReadStream(first)
var parse = ndjson.parse(args)
var serializer = ndjson.serialize(args)
inputStream.pipe(parse).pipe(serializer).pipe(process.stdout)
...function serialize(opts) {
return through.obj(opts, function(obj, enc, cb) {
cb(null, stringify(obj) + EOL)
})
}...
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()
...