Skip to content

simple-api-stream

Streaming utilities for incremental JSON, XML, CSV, TOML, INI, YAML, and SSE processing built on the Web Streams API.

Text is parsed chunk by chunk into a flat sequence of events — SAJ (Simple API for JSON), SAX (Simple API for XML), SAC (Simple API for CSV), SAT (Simple API for TOML), SAI (Simple API for INI), SAY (Simple API for YAML), and SSE events (text/event-stream). You can consume the events directly, rebuild JavaScript objects / ASTs / DOM nodes from them, convert between formats, or serialize them back into text. Because every component is a standard ReadableStream, WritableStream, or TransformStream, they compose naturally with pipeThrough() / pipeTo() and respect backpressure.

✨ Highlights

  • Zero external runtime dependencies
  • Web Streams native — works anywhere Web Streams are supported (Node.js, browsers, Deno, Bun, edge runtimes, …)
  • TypeScript-first ESM packages — ships with full type definitions (also directly require()-able via Node.js require(esm))
  • Modular monorepo — install only the format packages you need
  • Cross-format bridges — optional ./json entry points bridge XML, CSV, TOML, INI, and YAML event streams directly to and from SAJ (JSON) event streams, plus ./toml bridging INI ⇔ TOML
  • Fetch Response helpers — parseJSONResponse, parseXMLResponse, parseCSVResponse, parseTOMLResponse, parseINIResponse, parseYAMLResponse, and parseSSEResponse with automatic Content-Type validation and charset detection

📦 Packages

Package npm Description
@simple-api-stream/core npm Core event classes (SAEvent, StartDocumentEvent, EndDocumentEvent, ErrorEvent, CommentEvent), parser interfaces (SimpleApiParser), and Fetch Response helpers (responseToTextStream, ResponseStreamError)
@simple-api-stream/json npm Streaming JSON (SAJ) parser, object materializer, serializer, imperative builder, and parseJSONResponse (including NDJSON / JSONL / RFC 7464 json-seq & JSONC)
@simple-api-stream/xml npm Streaming XML (SAX) parser, AST & DOM converters, serializer, imperative builder, parseXMLResponse, and optional SAJ bridge (@simple-api-stream/xml/json)
@simple-api-stream/csv npm Streaming CSV (SAC) parser, row object converters, serializer, imperative builder, parseCSVResponse, and optional SAJ bridge (@simple-api-stream/csv/json)
@simple-api-stream/toml npm Streaming TOML (SAT) parser, object converters, serializer, imperative builder, parseTOMLResponse, and optional SAJ bridge (@simple-api-stream/toml/json)
@simple-api-stream/ini npm Streaming INI (SAI) parser, object converters, serializer, imperative builder, parseINIResponse, and optional SAT/SAJ bridges (@simple-api-stream/ini/toml, @simple-api-stream/ini/json)
@simple-api-stream/yaml npm Streaming YAML 1.2 (SAY) parser, object converters (with anchors/aliases & merge keys), serializer, imperative builder, parseYAMLResponse, and optional SAJ bridge (@simple-api-stream/yaml/json)
@simple-api-stream/sse npm Streaming Server-Sent Events (text/event-stream) parser, serializer, and parseSSEResponse

⚡ Quick Example

import { parseJSONResponse } from "@simple-api-stream/json";

const response = await fetch("https://example.com/data.ndjson");
for await (const item of parseJSONResponse(response)) {
  console.log(item);
}

Or compose the underlying Web Streams directly:

import {
  JSONTextToSAJTransformStream,
  SAJToObjectTransformStream,
} from "@simple-api-stream/json";

const response = await fetch("https://example.com/data.json");
const objects = response.body!
  .pipeThrough(new TextDecoderStream())
  .pipeThrough(new JSONTextToSAJTransformStream())
  .pipeThrough(new SAJToObjectTransformStream());

for await (const obj of objects) {
  console.log(obj);
}

🔗 Links

Popular repositories Loading

  1. simple-api-stream simple-api-stream Public

    Streaming JSON, XML, CSV, TOML, INI, YAML, and SSE parsers and serializers built on the Web Streams API

    TypeScript

  2. .github .github Public

Repositories

Showing 2 of 2 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…