Skip to content

feat: add JSON Lines (JSONL/NDJSON) reader/writer#55

Merged
alvinreal merged 1 commit intomainfrom
fix/issue-26
Feb 22, 2026
Merged

feat: add JSON Lines (JSONL/NDJSON) reader/writer#55
alvinreal merged 1 commit intomainfrom
fix/issue-26

Conversation

@alvinreal
Copy link
Owner

Implements JSON Lines (JSONL / NDJSON) format support.

Changes

  • Parser (from_str, from_reader): each non-empty line is parsed as a JSON value; the result is always an array
  • Writer (to_string): each array element becomes one compact JSON line; non-array values become a single line
  • Empty lines and whitespace-only lines are skipped during parsing
  • Error messages include the offending line number for invalid JSON
  • Mixed types per line are fully supported (objects, arrays, primitives, null)
  • CLI integration: -f jsonl / -t jsonl, auto-detect from .jsonl and .ndjson extensions
  • Made json_to_value and value_to_json in formats::json pub(crate) so JSONL can reuse them
  • 25+ unit tests: parsing, serialization, round-trips, empty input, unicode, error cases

Fixes #26

Implements JSONL format support:
- Parser: each non-empty line → JSON value, result is always an array
- Writer: each array element → one compact JSON line, trailing newline
- Empty lines and whitespace-only lines are skipped
- Error messages include line numbers for invalid JSON
- Mixed types per line supported (objects, arrays, primitives)
- CLI integration: -f jsonl/-t jsonl, auto-detect from .jsonl/.ndjson
- Comprehensive tests: parsing, serialization, round-trips, edge cases

Fixes #26
@alvinreal alvinreal merged commit 46fe72c into main Feb 22, 2026
6 checks passed
@alvinreal alvinreal deleted the fix/issue-26 branch February 22, 2026 06:39
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
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.

JSON Lines reader/writer

1 participant