I have a 5GB JSON file which is an array of objects with fixed structure:
[
{
"first": "John",
"last": "Doe",
"email": "john.doe@yahoo.com"
},
{
"first": "Anne",
"last": "Ortha",
"email": "anne.ortha@hotmail.com"
},
....
]
I know that I can try to parse this file using the code shown in How can I deserialize JSON with a top-level array using Serde?:
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct User {
first: String,
last: String,
email: String,
}
let users: Vec<User> = serde_json::from_str(file)?;
There are multiple problems:
- It is first read as a string as a whole
- After reading as string, it converts it into a vector of
Userstructs (I don't want that)
I tried How I can I lazily read multiple JSON values from a file/stream in Rust? but it reads the whole file before printing anything and it prints the whole structure at once inside the loop. I was expecting one object at a time in the loop:
Ideally, parsing and processing of the (parsed) User object should happen simultaneously in two separate threads/tasks/routines or by making use of channel.
