feat(ReadableStream): add .jsonl() method for parsing newline-delimited JSON#25757
feat(ReadableStream): add .jsonl() method for parsing newline-delimited JSON#25757robobun wants to merge 1 commit into
Conversation
…ed JSON
Adds a new `.jsonl()` method to ReadableStream that returns an async iterable
for parsing newline-delimited JSON (JSONL/NDJSON) streams.
Example usage:
```js
for await (const object of response.body.jsonl()) {
console.log(object);
}
```
The implementation:
- Reads from the stream chunk by chunk as text
- Buffers incomplete lines across chunks
- Parses complete lines as JSON and yields each object
- Handles trailing content without a final newline
- Skips empty/whitespace-only lines
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
@alii What do you think of this approach? This adds a .jsonl() method to ReadableStream for parsing newline-delimited JSON streams. I'd appreciate your review! |
WalkthroughAdds a new Changes
Possibly related PRs
Suggested reviewers
Pre-merge checks✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (6)
🧰 Additional context used📓 Path-based instructions (6)src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js}📄 CodeRabbit inference engine (src/js/CLAUDE.md)
Files:
src/js/{builtins,node,bun,thirdparty,internal}/**/*.ts📄 CodeRabbit inference engine (src/js/CLAUDE.md)
Files:
src/bun.js/bindings/**/*.cpp📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}📄 CodeRabbit inference engine (test/CLAUDE.md)
Files:
**/*.test.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/**/*.test.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (33)📓 Common learnings📚 Learning: 2025-10-17T20:50:58.644ZApplied to files:
📚 Learning: 2025-10-04T21:17:53.040ZApplied to files:
📚 Learning: 2025-10-19T02:52:37.412ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-10-01T21:59:54.571ZApplied to files:
📚 Learning: 2025-11-24T18:37:47.899ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-10-11T15:19:30.301ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-11-03T20:43:06.996ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-10-18T20:50:47.750ZApplied to files:
📚 Learning: 2025-09-05T19:49:26.188ZApplied to files:
📚 Learning: 2025-09-05T19:49:26.188ZApplied to files:
📚 Learning: 2025-11-24T18:37:11.466ZApplied to files:
📚 Learning: 2025-12-23T06:50:31.577ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-09-25T22:07:13.851ZApplied to files:
📚 Learning: 2025-10-26T01:32:04.844ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-10-19T02:44:46.354ZApplied to files:
📚 Learning: 2025-10-18T05:23:24.403ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-06T00:58:23.965ZApplied to files:
📚 Learning: 2025-10-25T17:20:19.041ZApplied to files:
🧬 Code graph analysis (3)src/bun.js/bindings/webcore/JSReadableStream.cpp (2)
src/bun.js/bindings/ZigGlobalObject.h (1)
test/js/web/streams/readablestream-jsonl.test.ts (1)
🔇 Additional comments (11)
Comment |
|
Closing this PR because it has been inactive for more than 90 days. |
Summary
Adds a new
.jsonl()method toReadableStreamthat returns an async iterable for parsing newline-delimited JSON (JSONL/NDJSON) streams.Example usage
How it works
Files changed
src/js/builtins/ReadableStream.ts- AddedreadableStreamToJSONL()implementationsrc/bun.js/bindings/webcore/JSReadableStream.cpp- Added C++ binding forjsonlsrc/bun.js/bindings/webcore/ReadableStream.cpp- AddedZigGlobalObject__readableStreamToJSONLsrc/bun.js/bindings/ZigGlobalObject.h- Added declaration and cached function slotpackages/bun-types/overrides.d.ts- Added TypeScript typestest/js/web/streams/readablestream-jsonl.test.ts- Added 15 testsTest plan
bun bd test test/js/web/streams/readablestream-jsonl.test.ts🤖 Generated with Claude Code