kinetex - v1.0.0-rc.1
    Preparing search index...

    Function readJSONStream

    • Parse a streaming JSON response (not NDJSON).

      Unlike NDJSON which requires newline-delimited JSON objects, this parser handles a stream of JSON data where objects may be split across chunks. Uses a state machine to handle partial JSON values.

      Type Parameters

      • T = unknown

      Parameters

      • response: Response

        The fetch Response.

      • options: ResponseParseOptions & {
            onObject?: (obj: T) => void;
            onParseError?: (err: unknown, partial: string) => void;
        } = {}

        Parse options + onObject/onParseError callbacks.

        • OptionalonObject?: (obj: T) => void

          Called when a complete object is parsed

        • OptionalonParseError?: (err: unknown, partial: string) => void

          Called on parse errors (skip bad objects)

      Returns AsyncGenerator<T>

      Each parsed JSON object as type T.

      If the streaming JSON buffer exceeds 10MB.

      // For a response streaming: {"a":1}{"a":2}{"a":3}
      for await (const obj of readJSONStream(response)) {
      console.log(obj); // {a:1}, {a:2}, {a:3}
      }