json-stream-lite 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +10 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # json-stream-lite
4
4
 
5
- A lightweight, memory-efficient streaming JSON parser and stringifier for JavaScript and TypeScript. Process large JSON files without loading them entirely into memory.
5
+ A lightweight, memory-efficient, zero-dependency streaming JSON parser and stringifier written in TypeScript. Process large JSON files without loading them entirely into memory.
6
6
 
7
7
  ## Features
8
8
 
@@ -58,7 +58,7 @@ const parser = new JsonObject()
58
58
  parser.feed(...new TextEncoder().encode(json))
59
59
 
60
60
  // Iterate through key-value pairs without loading the entire object
61
- for (const [keyEntity, valueEntity] of parser.members()) {
61
+ for (const { key: keyEntity, value: valueEntity } of parser) {
62
62
  const key = keyEntity.read()
63
63
  const value = valueEntity.read().read()
64
64
  console.log(`${key}: ${value}`)
@@ -96,8 +96,9 @@ async function processStream(stream: ReadableStream<Uint8Array>) {
96
96
  const parser = new JsonObject(stream)
97
97
 
98
98
  // Asynchronously iterate through members
99
- for await (const [keyEntity, valueEntity] of parser.membersAsync()) {
100
- const key = keyEntity.read()
99
+ for await (const { key: keyEntity, value: valueEntity } of parser) {
100
+ // If you want to read the key, make sure you call .read() before you read the value
101
+ const key = await keyEntity.readAsync()
101
102
  const value = await valueEntity.readValueAsync()
102
103
  console.log(`${key}: ${value}`)
103
104
  }
@@ -202,8 +203,8 @@ async function processLargeFile(filePath: string) {
202
203
  const stream = createReadStream(filePath)
203
204
  const parser = new JsonObject(stream)
204
205
 
205
- for await (const [keyEntity, valueEntity] of parser) {
206
- const key = keyEntity.read()
206
+ for await (const { key: keyEntity, value: valueEntity } of parser) {
207
+ const key = await keyEntity.readAsync()
207
208
  const value = await valueEntity.readValueAsync()
208
209
 
209
210
  // Process each key-value pair without loading entire file
@@ -221,7 +222,7 @@ const json = '{"users": [{"name": "Alice"}, {"name": "Bob"}]}'
221
222
  const parser = new JsonObject()
222
223
  parser.feed(...new TextEncoder().encode(json))
223
224
 
224
- for (const [keyEntity, valueEntity] of parser) {
225
+ for (const { key: keyEntity, value: valueEntity } of parser) {
225
226
  const key = keyEntity.read()
226
227
  const value = valueEntity.read()
227
228
 
@@ -260,8 +261,8 @@ async function processApiResponse(url: string) {
260
261
  const response = await fetch(url)
261
262
  const parser = new JsonObject(response.body!)
262
263
 
263
- for await (const [keyEntity, valueEntity] of parser.membersAsync()) {
264
- const key = keyEntity.read()
264
+ for await (const { key: keyEntity, value: valueEntity } of parser) {
265
+ const key = await keyEntity.readAsync()
265
266
  const value = await valueEntity.readValueAsync()
266
267
  console.log(`Processing ${key}:`, value)
267
268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-stream-lite",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "A lightweight, memory-efficient, zero-dependency streaming JSON parser and stringifier for JavaScript and TypeScript. It works in both Node.js and browser environments.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",