Skip to content
JSON

Streaming (NDJSON)

Newline-delimited JSON for streaming.

By EZ4Code Team
ndjsonstreamingjsonl

Code

{"name":"Alice","id":1}
{"name":"Bob","id":2}
{"name":"Charlie","id":3}

// Each line is a self-contained JSON object.
// NDJSON lets parsers emit records incrementally
// without loading the whole file into memory.

// Read in Node.js:
// const rl = readline.createInterface({ input: fs.createReadStream("data.ndjson") });
// rl.on("line", line => console.log(JSON.parse(line)));

Explanation

NDJSON (newline-delimited JSON) places one JSON object per line so consumers can parse records incrementally. It avoids the memory cost of loading a single huge array and supports append-only logs. Each line must be valid JSON on its own, with no trailing comma or multi-line objects.

More JSON Snippets