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-streamVerified import paths — ran on the pinned version, not inferred.
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.
Migrate to actively maintained NDJSON streaming libraries like `ndjson` or `JSONStream` or `ld-jsonstream` (a different package with a similar name) for production use.
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.Create a `ldjson-stream.d.ts` declaration file or use a modern, actively maintained library that provides built-in TypeScript support.
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.Use the CommonJS `require` syntax: `const ldj = require('ldjson-stream');` and access methods as `ldj.parse()` and `ldj.serialize()`.If malformed JSON lines should be ignored, instantiate the parser with `{ strict: false }`: `ldj.parse({ strict: false })`. Otherwise, ensure input data integrity.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.No dependency data recorded yet.