I am using JsonPath to retrive an array from a ~30 MB json file. The reason for that is when loading the file into a bufferedReader
, the app crashes due to lack of memory.
The problem is it takes so long (~2 min) to get one array using one call. When enabling more memory to the app through setting largeHeap = true
, the whole process (buffering then straightforward json-parsing) takes less than 10 seconds.
My method is simple (kotlin):
val indexes: List<String> = JsonPath.read(stream, "$.root.word")
Here, stream is a InputStream (GZIPInputStream). No matter the size of the retrived array (some have more than 1000 elements, where other have less than 20) it still takes around the same time.
I know it is not supposed to be that slow. What am I missing?
And if that is always the case, is there any suggestion on how to parse a large json file without loading it into memory?