
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
@piadina/fetch-jsonl
Advanced tools
Stream and parse (**JSON Lines**)[https://jsonlines.org/] directly with fetch. Yields parsed JSON objects one line at a time.
Stream and parse (JSON Lines)[https://jsonlines.org/] directly with fetch. Yields parsed JSON objects one line at a time.
npm install @piadina/fetch-jsonl
There are two ways to use this package:
Use the default export for quick, one-off requests. This is the simplest way to fetch and parse JSON Lines.
import fetch from "@piadina/fetch-jsonl";
interface TestItem {
id: number;
name: string;
createdAt?: string;
}
for await (const obj of fetch<TestItem>("https://example.com/data.jsonl")) {
console.log(obj.id, obj.name);
}
Use createInstance when you need to reuse a configured fetcher or want access to all HTTP methods (GET, POST, PUT, PATCH, DELETE). This approach is useful for:
import { createInstance } from "@piadina/fetch-jsonl";
interface TestItem {
id: number;
name: string;
createdAt?: string;
}
const fetcher = createInstance();
for await (const obj of fetcher.get<TestItem>("https://example.com/data.jsonl")) {
console.log(obj.id, obj.name);
}
All methods return an AsyncGenerator that yields parsed JSON objects one line at a time.
fetcher.get<T, TError>(url, init?) // GET request
fetcher.post<T, TError>(url, init?) // POST request
fetcher.put<T, TError>(url, init?) // PUT request
fetcher.patch<T, TError>(url, init?) // PATCH request
fetcher.delete<T, TError>(url, init?) // DELETE request
<T = unknown, TError extends Error = Error>(
url: RequestInfo | URL,
init?: RequestInit
) => AsyncGenerator<Awaited<T>, void, unknown>
url — RequestInfo | URL — The endpoint to fetch from (URL string or Request object)init — RequestInit — Optional fetch configuration (headers, body, etc.)T — Type of parsed JSON objects (defaults to unknown)TError — Custom error type for JSON parsing failures (defaults to Error)AsyncGenerator<T> — Stream of parsed JSON objects, one per line
// Basic usage with type inference
for await (const item of fetcher.get<User>('/api/users.jsonl')) {
console.log(item.name); // TypeScript knows item is User
}
// With custom error handling
try {
for await (const data of fetcher.post<Data, ValidationError>('/api/data', {
body: JSON.stringify({ query: 'test' }),
headers: { 'Content-Type': 'application/json' }
})) {
console.log(data);
}
} catch (error) {
// error is typed as ValidationError
}
try {
for await (const obj of fetcher.get<TestItem>('https://api.test/get-data.jsonl')) {
console.log(obj);
}
} catch (err) {
console.error("Invalid JSON line:", err);
}
You can modify requests before they're sent using beforeRequest hooks. This is useful for adding authentication headers, request IDs, or other common request modifications.
const addAuthHook = (request: Request) => {
const newRequest = new Request(request, {
headers: {
...Object.fromEntries(request.headers.entries()),
'Authorization': 'Bearer test-token',
},
});
return newRequest;
};
const fetcher = createInstance({
hooks: {
beforeRequest: [addAuthHook],
},
});
for await (const obj of fetcher.get<TestItem>('https://api.test/get-data.jsonl')) {
console.log(obj);
}
How it works:
beforeRequest hooks receive the original Request objectRequest object with modificationsvoid, the request passes through unchangedTransform JSON data during parsing using a custom reviver function. This is useful for converting string dates to Date objects, parsing numbers, or transforming any data structure during JSON parsing.
interface TestItemWithDate {
id: number;
name: string;
createdAt?: Date;
}
const reviver = (key: string, value: unknown): unknown => {
if (key === 'createdAt' && typeof value === 'string') {
return new Date(value);
}
return value;
};
const fetcher = createInstance({ reviver });
for await (const obj of fetcher.get<TestItemWithDate>('https://api.test/get-data.jsonl')) {
console.log(obj.createdAt instanceof Date); // true - automatically converted!
}
How it works:
key and its value as parametersUse a custom fetch implementation instead of the browser's built-in fetch. This is useful for adding custom retry logic, advanced authentication, request/response interceptors, or when working with libraries like ky, axios, or node-fetch.
import ky from 'ky';
const fetcher = createInstance({ fetchImpl: ky });
for await (const obj of fetcher.get<TestItem>('https://api.test/get-data.jsonl')) {
console.log(obj);
}
How it works:
fetch with any compatible HTTP clientfetch APIky (lightweight HTTP client), node-fetch (Node.js), or custom fetch wrappersFAQs
Stream and parse (**JSON Lines**)[https://jsonlines.org/] directly with fetch. Yields parsed JSON objects one line at a time.
The npm package @piadina/fetch-jsonl receives a total of 5 weekly downloads. As such, @piadina/fetch-jsonl popularity was classified as not popular.
We found that @piadina/fetch-jsonl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.