Bun.JSONL.parse()
Parse a complete JSONL input and return an array of all parsed values.
Uint8Array:
Uint8Array, a UTF-8 BOM at the start of the buffer is automatically skipped.
Error handling
If the input contains invalid JSON,Bun.JSONL.parse() throws a SyntaxError:
Bun.JSONL.parseChunk()
For streaming scenarios, parseChunk parses as many complete values as possible from the input and reports how far it got. This is useful when receiving data incrementally (e.g., from a network stream) and you need to know where to resume parsing.
Return value
parseChunk returns an object with four properties:
| Property | Type | Description |
|---|---|---|
values | any[] | Array of successfully parsed JSON values |
read | number | Number of bytes (for Uint8Array) or characters (for strings) consumed |
done | boolean | true if the entire input was consumed with no remaining data |
error | SyntaxError | null | Parse error, or null if no error occurred |
Streaming example
Useread to slice off consumed input and carry forward the remainder:
Byte offsets with Uint8Array
When the input is a Uint8Array, you can pass optional start and end byte offsets:
read value is always a byte offset into the original buffer, making it easy to use with TypedArray.subarray() for zero-copy streaming:
Error recovery
Unlikeparse(), parseChunk() does not throw on invalid JSON. Instead, it returns the error in the error property, along with any values that were successfully parsed before the error:
Supported value types
Each line can be any valid JSON value, not just objects:Performance notes
- ASCII fast path: Pure ASCII input is parsed directly without copying, using a zero-allocation
StringView. - UTF-8 support: Non-ASCII
Uint8Arrayinput is decoded to UTF-16 using SIMD-accelerated conversion. - BOM handling: UTF-8 BOM (
0xEF 0xBB 0xBF) at the start of aUint8Arrayis automatically skipped. - Pre-built object shape: The result object from
parseChunkuses a cached structure for fast property access.