I am looking to load a large json file over 100GB+. The objects in this file aren't static and are almost never the same. I found this crate called nop-json https://crates.io/crates/nop-json/2.0.5. but I was unable to get it to the work in the way that I want. This is my current solution but it feels a bit like cheating.
let file = File::open("./file.json")?;
let reader = BufReader::new(file);
for line in reader.lines() {
//code
}
I am reading the file like a text file and itterating that way. the problem is that with this solution I am reading it as a string and that it loads the entire file into memory.
I am new to rust so I am looking for some help on this problem. I have a succesful implementation in python and it works great but its too slow.
edit:
Thank you for the replies so far here is some more information:
My *.json file has 1 array containing milions of objects. example:
[
{
"foo": "bar",
"bar": "foor"
},
{
"foo": "bar",
"bar": "foor"
},
{
"foo": "bar",
"bar": "foor"
},
{
"foo": "bar",
"bar": "foor"
}
]
etc..
The problem with reading the file as a text file this way is that not every object is 1 line exactly. The amount of lines for an object is not the same.
Some possible soltuion might be to read a chunk of the file and then check where the json object ended via something like a pattern }, {
. But this seems inaficiant.