Crates.io | streamson-tokio |
lib.rs | streamson-tokio |
version | 7.1.0 |
source | src |
created_at | 2020-05-29 22:26:27.039596 |
updated_at | 2021-05-10 20:21:23.287364 |
description | Tokio and streamson integration library |
homepage | |
repository | https://github.com/shenek/streamson |
max_upload_size | |
id | 247532 |
size | 10,115 |
A library which integrates streamson with tokio. So that you can easily process JSONs using asynchronous rust.
use std::io;
use streamson_lib::{error, matcher};
use streamson_tokio::decoder::Extractor;
use tokio::{fs, stream::StreamExt};
use tokio_util::codec::FramedRead;
let mut file = fs::File::open("/tmp/large.json").await?;
let matcher = matcher::Combinator::new(matcher::Simple::new(r#"{"users"}[]"#).unwrap())
| matcher::Combinator::new(matcher::Simple::new(r#"{"groups"}[]"#).unwrap());
let extractor = Extractor::new(matcher);
let mut output = FramedRead::new(file, extractor);
while let Some(item) = output.next().await {
let (path, data) = item?;
// Do something with extracted data
}