Registry / serialization / ldjson-stream

ldjson-stream

JSON →
library1.2.1jsnpmunverified

ldjson-stream is a streaming library designed for parsing and serializing line-delimited JSON (also known as NDJSON or JSON Lines). It provides two primary Transform streams: `parse()` for converting newline-separated JSON strings into JavaScript objects, and `serialize()` for converting JavaScript objects into newline-delimited JSON strings. The package is lightweight and was last updated over a decade ago, with its current stable version being 1.2.1. Due to its age, it exclusively uses CommonJS modules and does not offer native ESM support or TypeScript type definitions. While it remains functional for basic NDJSON processing in older Node.js environments, its abandoned status means it lacks ongoing maintenance, security updates, or compatibility enhancements for modern JavaScript ecosystems. It was a minimalist solution for streaming JSON in its time.

npm install ldjson-stream
INSTALL
IMPORT
SIG · LDJSON-STREAM
L
ldjson-stream
serializationjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ldj
const ldj = require('ldjson-stream')
import ldj from 'ldjson-stream'
This package is CommonJS-only and does not support ES module imports. Attempting to use `import` will result in a module resolution error.
ldj.parse
const ldj = require('ldjson-stream'); const parseStream = ldj.parse();
import { parse } from 'ldjson-stream'
`parse` is a method of the default exported CommonJS module, not a named export. It returns a Transform stream.
ldj.serialize
const ldj = require('ldjson-stream'); const serializeStream = ldj.serialize();
import { serialize } from 'ldjson-stream'
`serialize` is a method of the default exported CommonJS module, not a named export. It returns a Transform stream.

Demonstrates how to use `ldj.serialize()` to convert JavaScript objects into line-delimited JSON and then `ldj.parse()` to convert them back into objects, simulating a full data stream.

const fs = require('fs'); const { Readable } = require('stream'); const ldj = require('ldjson-stream'); const jsonData = [ { id: 1, name: 'Alice', role: 'Engineer' }, { id: 2, name: 'Bob', role: 'Designer' }, { id: 3, name: 'Charlie', role: 'PM' } ]; // Create a readable stream from an array of objects const inputReadable = new Readable({ objectMode: true, read() { if (jsonData.length) { this.push(jsonData.shift()); } else { this.push(null); } } }); // Simulate reading from a file, serializing, and then parsing inputReadable .pipe(ldj.serialize()) .pipe(ldj.parse({ strict: false })) // Use strict: false to be resilient to malformed lines if needed .on('data', (obj) => { console.log('Parsed object:', obj); }) .on('end', () => { console.log('All objects processed.'); }) .on('error', (err) => { console.error('Stream error:', err.message); });
Debug
Known issues
breakingThe package is abandoned and has not been updated in over a decade. It does not receive security patches, bug fixes, or compatibility updates for newer Node.js versions or JavaScript features. Consider modern alternatives for new projects.
fix
Migrate to actively maintained NDJSON streaming libraries like `ndjson` or `JSONStream` or `ld-jsonstream` (a different package with a similar name) for production use.
affects: >=1.0.0
gotchaThis library is strictly CommonJS. It cannot be directly imported into an ES Module project using `import` statements without Node.js's CJS-ESM interop features or a bundler configured for CJS fallback.
fix
For ES Module projects, consider dynamic `import('ldjson-stream')` or use a bundler (e.g., Webpack, Rollup) that handles CommonJS modules. Preferably, migrate to an ESM-native NDJSON library.
affects: >=1.0.0
gotchaThe library does not ship with TypeScript type definitions. Projects using TypeScript will require manual type declarations or `@ts-ignore` directives to use `ldjson-stream` safely.
fix
Create a `ldjson-stream.d.ts` declaration file or use a modern, actively maintained library that provides built-in TypeScript support.
affects: >=1.0.0
gotchaBy default, `ldj.parse()` operates in 'strict' mode, throwing a `SyntaxError` if any line contains invalid JSON. This can halt stream processing unexpectedly with malformed input.
fix
To gracefully handle invalid JSON lines, initialize the parser with `ldj.parse({ strict: false })`. This will cause the parser to discard malformed lines without emitting an error, allowing the stream to continue.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: ldj.parse is not a function
Attempting to import `ldjson-stream` using ES Module syntax (e.g., `import { parse } from 'ldjson-stream'`) or incorrectly destructing the CommonJS export.
fix
Use the CommonJS `require` syntax: `const ldj = require('ldjson-stream');` and access methods as `ldj.parse()` and `ldj.serialize()`.
SyntaxError: Unexpected token <char> in JSON at position <number>
The input stream contains a line that is not valid JSON, and the `ldj.parse()` stream is operating in its default strict mode.
fix
If malformed JSON lines should be ignored, instantiate the parser with `{ strict: false }`: `ldj.parse({ strict: false })`. Otherwise, ensure input data integrity.
Module not found: Can't resolve 'ldjson-stream' in <path>
An ES Module-enabled environment (e.g., a modern Node.js project with `"type": "module"` or a frontend bundler) is attempting to resolve `ldjson-stream` as an ESM module, but it's CJS-only.
fix
Either configure your bundler to handle CommonJS modules, use dynamic import `import('ldjson-stream').then(ldj => ...)`, or for Node.js, ensure `require()` is used in a CJS context. The recommended long-term fix is to migrate to an ESM-compatible library.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Meta
1
Resources
ldjson-stream — npm install ldjson-stream · libregistry