0

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.

2
  • If your JSON input is that big then you want to use the streaming API; it is doable, now you need to be more precise about what you really want. Reading an element is easy, what to do with it is the question. Commented Apr 2, 2015 at 13:05
  • i added some more explanation, maybe that will help Commented Apr 2, 2015 at 13:14

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.