Registry / devops / schema-stream

schema-stream

JSON →
library3.2.2jsnpmunverified

Type-safe JSON streaming parser with progressive data access for Node.js, version 3.2.2. Allows parsing JSON incrementally from streams (e.g., HTTP responses, files) while validating against Zod schemas, enabling early access to parsed data before the full payload is available. Supports async iteration and partial data extraction. Requires Zod as a peer dependency at ^3.23.3. Ships with TypeScript types. Differentiates from generic JSON streaming parsers by integrating schema validation and progressive data access.

npm install schema-stream
INSTALL
IMPORT
SIG · SCHEMA-STREAM
S
schema-stream
devopsjavascriptv3.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

schemaStream
import { schemaStream } from 'schema-stream'
const schemaStream = require('schema-stream')
ESM-only package; CommonJS require will fail. TypeScript types are included.
createSchemaStream
import { createSchemaStream } from 'schema-stream'
import createSchemaStream from 'schema-stream'
Named export; default import is not available.
SchemaStream
import type { SchemaStream } from 'schema-stream'
import { SchemaStream } from 'schema-stream'
Type import only; SchemaStream is a type, not a runtime value.

Demonstrates progressive parsing of a JSON array of users from an HTTP response using a Zod schema.

import { createSchemaStream } from 'schema-stream'; import { z } from 'zod'; // Define a schema const UserSchema = z.object({ id: z.number(), name: z.string(), email: z.string().email() }); // Create a stream from an HTTP response const response = await fetch('https://api.example.com/users'); if (!response.body) throw new Error('No body'); const stream = createSchemaStream(UserSchema, response.body); // Process each parsed object as it arrives for await (const parsed of stream) { console.log(parsed); // { id: number, name: string, email: string } }
Debug
Known issues
breakingv3 dropped support for Node < 18, changed API from callback-based to async iterable, and renamed exports
fix
Upgrade to Node 18+, use async iteration with `createSchemaStream` instead of old `parseStream` callback
affects: >=3.0.0 <3.0.0
deprecatedImporting from 'schema-stream/stream' was removed in v3; use main entry point
fix
Change `import { ... } from 'schema-stream/stream'` to `import { ... } from 'schema-stream'`
affects: >=3.0.0
gotchaThe stream must be consumed sequentially; calling `next()` concurrently or skipping elements may cause incorrect behavior
fix
Always use `for await...of` or sequential async iteration. Do not manually call `.next()` concurrently.
affects: *
gotchaPartial objects are yielded as soon as a complete JSON object/array is parsed, not when all fields are valid against the schema
fix
Validate after collection if you need full object integrity, or use schema refinement to require all fields before yielding.
affects: *
gotchaMemory usage can increase if the stream is not consumed quickly, as parsed objects accumulate
fix
Consume the stream promptly; use backpressure or reduce buffer size if needed.
affects: *
Errors
Common errors & fixes
TypeError: schema_stream_1.createSchemaStream is not a function
Using default import instead of named import in ESM
fix
Change `import createSchemaStream from 'schema-stream'` to `import { createSchemaStream } from 'schema-stream'`
Cannot find module 'schema-stream' or its corresponding type declarations
Missing peer dependency 'zod' or incorrect TypeScript configuration
fix
Install zod: `npm install zod@^3.23.3` and ensure tsconfig includes 'esModuleInterop' and 'moduleResolution' set to 'node16' or 'bundler'
SyntaxError: Unexpected token 'export'
Using CommonJS require() on an ESM-only package
fix
Switch to ESM (use import statements) or use dynamic import: `const { createSchemaStream } = await import('schema-stream')`
Upgrade
Version history
3.2.2latest on npm
Audit
Dependencies
zodrequiredPeer dependency for schema definition and validation
Agent activity
9 hits · last 30 days
node
8
Resources
schema-stream — npm install schema-stream · libregistry