Registry / http-networking / jsonpipe

jsonpipe

JSON →
library2.2.0jsnpmunverified

jsonpipe is a lightweight, standalone AJAX client for consuming chunked (Transfer-Encoding: chunked) JSON responses in the browser. Version 2.2.0 (latest) ships TypeScript types. It exposes a single `flow` function with an API similar to jQuery.ajax, but tailored for streaming JSON delimited by double newlines (`\n\n`). No dependencies, supports IE8+, and allows per-chunk callbacks. Differentiators: minimal footprint, automatic delimiter-based JSON parsing, and configurable delimiter.

npm install jsonpipe
INSTALL
IMPORT
SIG · JSONPIPE
J
jsonpipe
http-networkingjavascriptv2.2.0
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.

flow
import { flow } from 'jsonpipe';
const jsonpipe = require('jsonpipe'); jsonpipe.flow(...);
ESM and TypeScript: named import. The default export is the flow function itself, but named import is correct for TS. No default export exists.
jsonpipe (default)
import jsonpipe from 'jsonpipe';
const jsonpipe = require('jsonpipe').default;
If using ESM without named imports, default import works. But TypeScript types recommend named import.
jsonpipe (CommonJS)
const jsonpipe = require('jsonpipe');
const { flow } = require('jsonpipe');
CommonJS require returns a function (the flow function) directly. Destructuring will fail.

Initializes a streaming GET request that logs each JSON chunk as it arrives, along with error and completion handlers.

import { flow } from 'jsonpipe'; // Sample endpoint that returns chunked JSON separated by \n\n flow('https://api.example.com/stream', { success: (data) => { console.log('Received chunk:', data); }, error: (msg) => { console.error('Error:', msg); }, complete: (statusText) => { console.log('Request completed with status:', statusText); }, timeout: 5000, method: 'GET' });
Debug
Known issues
gotchajsonpipe expects JSON objects separated by double newline (`\n\n`) by default. If the server uses a different delimiter, you must set the `delimiter` option.
fix
Set `delimiter` in the options object to the correct separator string.
affects: >=1.0.0
gotchaThe `data` option sends a request body. If `data` is not a string (e.g., FormData, File, Blob), you must set `disableContentType: true` to avoid overwriting the Content-Type header.
fix
Set `disableContentType: true` when sending non-string data.
affects: >=1.0.0
gotchajsonpipe only works in browser environments (IE8+). It relies on XMLHttpRequest and is not compatible with Node.js or server-side rendering.
fix
Use in browser context only. For Node.js streaming, consider alternatives like `fetch` with ReadableStream.
affects: >=1.0.0
gotchaThe `onHeaders` callback receives arguments (statusText, headers) but `headers` is an object, not a string. Some users expect a string header.
fix
Access individual header values via `headers['Content-Type']` or similar.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'flow' of undefined
Using CommonJS destructuring on the require result, which is a function, not an object.
fix
Use `const jsonpipe = require('jsonpipe'); jsonpipe.flow(...);` instead of `const { flow } = require('jsonpipe');`
Uncaught SyntaxError: Unexpected token < in JSON at position 0
Server returns HTML or invalid JSON; or delimiter not set correctly causing malformed chunks.
fix
Ensure server sends valid JSON objects separated by `\n\n` and set the correct `delimiter` option if different.
NetworkError: Failed to execute 'send' on 'XMLHttpRequest'
The request was aborted or a network issue occurred; or `withCredentials` not supported in some CORS configurations.
fix
Check server CORS headers and ensure `withCredentials` is used only if the server allows credentials.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
jsonpipe — npm install jsonpipe · libregistry