简体   繁体   中英

How to read very big JSON files in stream mode?

While working on an API implemented in Java and one of the operations requires to open a big JSON file and returns an object identified by a given string. The file in question is formed by an array of objects, tons of object, and it has no sense to read the whole file and create tons of Java objects into memory only to return one.

So, What is a good way to read the JSON file in stream mode?

One of excellent libraries for parsing large JSON files with minimal resources is the popular GSON library . It gets at the same effect of parsing the file as both stream and object. It handles each record as it passes, then discards the stream, keeping memory usage low.

Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types)

Look at this Detailed Tutorial for GSON approach,to solve it problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM