
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
json-response-stream
Advanced tools
Utility function for streaming JSON from LLM libraries such as Genkit
A tiny, powerful utility for streaming JSON from API responses, LLMs (like Genkit), and anywhere else you're getting a stream of JSON objects.
fetch
, LLM APIs, or any ReadableStreamnpm install json-response-stream
# or
yarn add json-response-stream
# or
pnpm add json-response-stream
import { jsonParser } from 'json-response-stream'
// Let's fetch some streaming data!
const response = await fetch('https://api.example.com/stream')
// The magic happens here ✨
for await (const data of jsonParser(response.body)) {
console.log('Got new data:', data)
// Do something cool with each JSON object as it arrives
}
import { jsonParser } from 'json-response-stream'
interface User {
id: number
name: string
role: string
}
const response = await fetch('https://api.example.com/users/stream')
// Type safety! 🛡️
for await (const user of jsonParser<User>(response.body)) {
console.log(`Welcome, ${user.name} the ${user.role}!`)
}
// server side:
const { stream } = await ai.generateStream('Suggest a complete menu for a pirate themed restaurant.')
const transformedStream = ReadableStream.from(stream).pipeThrough(
new TransformStream({
transform(chunk, controller) {
controller.enqueue(JSON.stringify(chunk))
}
})
)
// Send the stream to the client
sendStream(event, transformedStream)
// Client side:
const response = await fetch('/api/genkit/stream')
// Process each chunk as it comes in!
for await (const idea of jsonParser(response.body)) {
console.log(chunk.text)
}
jsonParser<T>(stream: ReadableStream): AsyncIterableIterator<T>
The star of the show! Creates an async iterator that processes a stream and yields JSON objects as they become available.
// Advanced example with fetch and AbortController
const controller = new AbortController()
const response = await fetch('https://api.example.com/stream', {
signal: controller.signal
})
setTimeout(() => controller.abort(), 5000) // Cancel after 5 seconds
try {
for await (const data of jsonParser(response.body)) {
console.log(data)
}
} catch (error) {
if (error.name === 'AbortError') {
console.log('Stream reading was cancelled! 🛑')
} else {
console.error('Error processing stream:', error)
}
}
jsonTransformStream<T>()
Creates a TransformStream for processing JSON chunks. Useful if you're working directly with the Streams API.
const transformedStream = someReadableStream
.pipeThrough(new TextDecoderStream())
.pipeThrough(jsonTransformStream())
safeParse<T>(str: string): T | null
A JSON.parse wrapper that never throws - returns null on invalid JSON.
hashString(str: string): string
A simple string hashing function used internally to detect duplicates.
Streaming APIs are awesome, but dealing with chunked JSON can be a pain. This library makes it seamless to:
Contributions welcome! Open an issue or PR on GitHub.
MIT - do awesome things with it!
package.json
npm run build && npm publish
Made with ❤️ by Jamie Curnow
FAQs
Utility function for streaming JSON from LLM libraries such as Genkit
The npm package json-response-stream receives a total of 3 weekly downloads. As such, json-response-stream popularity was classified as not popular.
We found that json-response-stream demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.