asyncjsonstream
Async JSON stream reader for selective parsing of large payloads. This is the
standalone home of Extract's AsyncJsonStreamReader implementation.
Why asyncjsonstream
- Stream through large JSON without deserializing the full payload.
- Selectively read keys, values, and arrays using a tokenized reader.
- Handles chunk boundaries and escaped strings correctly.
- Built on Tokio
AsyncRead. - No unsafe code.
Install
Quick start
use AsyncJsonStreamReader;
use Cursor;
async
Common patterns
- Read object entries with
next_object_entry. - Skip values by calling
next_object_entryagain without consuming the value. - Stream arrays with
start_array_item. - Parse string/number/bool with
read_string,read_number,read_boolean. - Deserialize a sub-object with
deserialize_object.
Error handling
All fallible operations return AsyncJsonStreamReaderError:
Iofor reader failuresJsonErrorfor malformed JSONUnexpectedTokenwhen the stream doesn't match the expected structure
MSRV
Minimum supported Rust version is 1.74.
Benchmark (Serde vs asyncjsonstream)
The examples folder includes a generator and benchmark for a single large JSON object with a
rows array. This comparison highlights the memory savings when you stream and skip large
fields instead of deserializing full objects.
Generate a 5GB fixture
Run benchmarks (macOS)
async deserializes each row into a serde_json::Value (higher memory). async-light only
reads id and skips other fields using tokens (low memory).
Results (MacBook Pro, macOS, 5GB file, payload 1KB)
| Mode | Rows | Elapsed (ms) | Max RSS (bytes) | Peak footprint (bytes) |
|---|---|---|---|---|
| async | 4,979,433 | 7,432 | 3,320,676,352 | 5,382,197,400 |
| async-light | 4,979,433 | 10,340 | 2,916,352 | 2,146,616 |
| serde | 4,979,433 | 6,662 | 10,902,372,352 | 14,253,713,704 |
Checksums matched across modes, confirming identical id aggregation.
License
Licensed under either of:
- Apache License, Version 2.0 (
LICENSE-APACHE) - MIT license (
LICENSE-MIT)
at your option.