JSON parser read an entry by entry from large JSON file JSON parser read an entry by entry from large JSON file json json

JSON parser read an entry by entry from large JSON file


With Jackson you can use a SAX-like approach (streaming) using a JsonParser object, in your case it would be something like this:

JsonFactory jsonFactory = new JsonFactory();JsonParser parser = jsonFactory.createParser(new File("/path/to/my/jsonFile"));// Map where to store your field-value pairs per objectMap<String, String> fields = new HashMap<String, String>();JsonToken token;while ((token = parser.nextToken()) != JsonToken.END_ARRAY) {    switch (token) {        // Starts a new object, clear the map        case START_OBJECT:            fields.clear();            break;        // For each field-value pair, store it in the map 'fields'        case FIELD_NAME:            String field = parser.getCurrentName();            token = parser.nextToken();            String value = parser.getValueAsString();            fields.put(field, value);            break;        // Do something with the field-value pairs        case END_OBJECT:            doSomethingWithTheObject(fields)            break;        }    }    parser.close();