Reputation: 579
I have the following json file
[{"key1":"value11", "key2":"value12"},{"key1":"value21", "key2":"value22"},...]
How can I get each json Object from that array using Jackson. One note here is that the json file is Big ~ 700MB. I want read JSON object one by one process and load data into database
step 1: {"key1":"value11", "key2":"value12"}
step 2: {"key1":"value21", "key2":"value22"}
...
so i need to load all that information into database. let say i have one table in database:
create table mytbl
(
key1 varchar2(100),
key2 varchar2(100)
)
so each key should go into his column.
Upvotes: 0
Views: 696
Reputation: 579
I want to share how I get that, maybe someone will use ...
ObjectMapper mapper = new ObjectMapper();
JsonParser parser = mapper.getJsonFactory().createJsonParser(new File(ConfigurationManager.jsonfile));
JsonToken token = parser.nextToken();
if (token == null) {
System.out.println("no json file");
}
if (!JsonToken.START_ARRAY.equals(token)) {
System.out.println("Expected an array");
}
while (!JsonToken.END_ARRAY.equals(parser.nextToken())) {
System.out.println(parser.readValueAsTree().toString()));
// parse json object here
}
parser.close();
Upvotes: 2