tpt-jsonl-stream 0.1.0

Streaming, zero-allocation JSON Lines (.jsonl) parser
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Example: stream-parse a JSON Lines buffer line by line.
//!
//! Run with: `cargo run -p tpt-jsonl-stream --example stream`

use std::io::BufReader;

use tpt_jsonl_stream::parse_jsonl;

fn main() {
    let data = b"{\"user\":\"alice\"}\n{\"user\":\"bob\"}\nNOT_JSON\n{\"user\":\"carol\"}\n";
    for (i, result) in parse_jsonl(BufReader::new(data.as_slice())).enumerate() {
        match result {
            Ok(value) => println!("line {}: {}", i + 1, value),
            Err(e) => eprintln!("line {}: {}", i + 1, e),
        }
    }
}