Skip to content

jsonl: NDJSON / JSON-Lines stream decoder#14

Merged
OmarAlJarrah merged 4 commits into
mainfrom
feat/jsonl
Jun 16, 2026
Merged

jsonl: NDJSON / JSON-Lines stream decoder#14
OmarAlJarrah merged 4 commits into
mainfrom
feat/jsonl

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Adds a jsonl package that decodes a stream of JSON values (JSON Lines / NDJSON)
into typed values via a range-over-func iterator — for consuming streaming JSON
APIs.

What's included

  • Decode[T any](r io.Reader) iter.Seq2[T, error] — yields each successive
    JSON value decoded into a T. Values may be separated by any JSON whitespace
    (newlines for NDJSON, or none), built on encoding/json's Decoder (incremental,
    no whole-stream buffering). Clean io.EOF ends iteration; a decode error
    (including a truncated final value) is surfaced once, then iteration stops.

Background

One of the streaming helpers deferred from the HTTP-value-types roadmap item. The
chunked-transfer side is already handled by net/http (the body is de-chunked
before Decode sees it).

Behavior changes

None — new package only.

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l . (clean)
  • go test -race ./... (all packages pass)
  • Covered: NDJSON order; bare scalars; a single value without a trailing newline;
    empty stream → no values; a malformed value mid-stream surfaces the error after
    the first value; a truncated final value surfaces an error; early break stops
    decoding.

🤖 Generated with Claude Code

OmarAlJarrah and others added 4 commits June 16, 2026 21:33
Generic Decode[T] over json.Decoder yielding stream values as iter.Seq2.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@OmarAlJarrah OmarAlJarrah merged commit 0e5c18e into main Jun 16, 2026
@OmarAlJarrah OmarAlJarrah deleted the feat/jsonl branch June 16, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant