jsonsurge
v1.0.6
Published
A JSON parsing utility for streaming data
Downloads
29
Readme
StreamJSONParser
StreamJSONParser is a JavaScript module that provides a way to parse JSON data from a readable stream in an asynchronous and efficient manner. It is particularly useful when dealing with streaming JSON data, such as data received from server-sent events (SSE) or other real-time data sources.
Installation
You can install StreamJSONParser using npm or yarn:
npm install stream-json-parser
or
yarn add stream-json-parser
Usage
To use StreamJSONParser, you need to import it into your JavaScript or TypeScript code:
import streamJSONParser from 'stream-json-parser';
Example Usage
Here is an example of how to use StreamJSONParser to parse JSON data from a readable stream:
import streamJSONParser from 'stream-json-parser';
// Create a ReadableStream (e.g., from a fetch response)
const response = await fetch('https://example.com/streaming-data');
const stream = response.body;
for await (const chunk of streamjsonparser(response.body)) {
console.log(chunk)
}
How It Works
The streamJSONParser
function accepts a readable stream as its input and returns an asynchronous generator that yields parsed JSON objects as they are received from the stream.
Contributing
If you'd like to contribute to StreamJSONParser, please open an issue or submit a pull request on GitHub.
License
StreamJSONParser is licensed under the MIT License.
Acknowledgments
StreamJSONParser is inspired by the need for efficient parsing of streaming JSON data in real-time applications.
About
StreamJSONParser is maintained by Gaurav mishra. You can contact me at [email protected].
For more information, visit the GitHub repository.