2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JsonLines (NDJSON) の IN / OUT に対応した json-seq-stream@1.0.7 リリースしました。

Last updated at Posted at 2025-07-18

はじめに

前回の記事では、application/json-seq に対応した Node.js 向けストリーム変換ライブラリ json-seq-stream の初期リリース (v1.0.5) について紹介しました。

あれから約1週間、以下のアップデートを経て、ついに application/jsonl / application/x-ndjson にも IN / OUT 双方 対応した v1.0.7 をリリースしました!


進化の流れ

  • v1.0.5: application/json-seq の 入力 に対応
  • v1.0.6: 出力にも対応し、クラス名を「Input/Output」で整理
  • v1.0.7: NDJSON / JSONL 対応 & 汎用変換の基礎モジュール化

機能サマリ(v1.0.7

  • 🆕 application/jsonl / application/x-ndjson 入出力に対応
  • 🧱 パース / シリアライズ処理のストリームクラスを汎用化
  • 🧑‍🏫 README.md に NDJSON 使用例を追加
  • 🔁 クラス名の統一・整理(旧クラスは v2.0.0 で削除予定)

追加された主なクラス

クラス名 役割
InputJsonLinesStream<T> NDJSON/JSONL から object stream への変換
OutputJsonLinesStream<T> object stream から NDJSON/JSONL への変換
ParseStream<T> 任意の からオブジェクト T への変換
StringifyStream<T> オブジェクト T を に変換
TextSplitStream / TextJoinStream デリミタによる分割・連結
SequenceToRecordStream / RecordToSequenceStream ストリームの chunk 境界を構造的に処理

使い方(NDJSON を例に)

実際に使ってみる

ここでは NDJSON を対象に、ストリームとして読み書きする最小例を紹介します。

読み込み(IN)

import { InputJsonLinesStream } from 'json-seq-stream'

const ndjsonInput = createReadStream('data.jsonl')
  .pipe(new InputJsonLinesStream<MyType>({}))

書き出し(OUT)

import { OutputJsonLinesStream } from 'json-seq-stream'

const jsonOutput = Readable.from(data)
  .pipe(new OutputJsonLinesStream<MyType>({}))

v1.0.7 以降の方向性

より柔軟な構成を可能にするため、各フォーマット変換はすべて汎用的な変換クラスの組み合わせで構築されています。これにより、次のようなカスタムフォーマットも簡単に実装可能です

この設計により、ログ、TSV、カスタムバイナリプロトコルなど、JSON 以外のフォーマットにも応用可能です。

最後に

Node.js で json-seq, jsonl, ndjson のようなストリーム形式を扱うニーズは増えてきています。

本ライブラリはそのような用途にフォーカスしつつ、拡張性・再利用性にも配慮した構成になっています。ぜひお試しください!

おまけ:ネーミングに関して

- OutputJsonSequenceStfingifyStream
+ OutputJsonSequenceStringifyStream

今後も地道に typo を潰していきます 🙃

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?