Bun.JSONL.parse()
Parse a complete JSONL input and return an array of all parsed values.
Uint8Array:
Uint8Array input, Bun skips a UTF-8 BOM at the start of the buffer.
Error handling
If the input contains invalid JSON and no values were successfully parsed,Bun.JSONL.parse() throws a SyntaxError. If at least one value was parsed before the error, it returns the parsed values without throwing.
Bun.JSONL.parseChunk()
For streaming, parseChunk parses as many complete values as it can from the input and reports how far it got. That way you know where to resume when data arrives incrementally (for example, from a network stream).
Return value
parseChunk returns an object with four properties:
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. Use it 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: Bun parses pure ASCII input directly without copying, using a zero-allocation
StringView. - UTF-8 support: Bun decodes non-ASCII
Uint8Arrayinput to UTF-16 using SIMD-accelerated conversion. - BOM handling: Bun automatically skips a UTF-8 BOM (
0xEF 0xBB 0xBF) at the start of aUint8Array. - Pre-built object shape: The result object from
parseChunkuses a cached structure for fast property access.