Jackson Streaming API – read and write json

In this post,we will see how can we will use jackson streaming API to read and write JSON .

Java JSON Tutorial Content:

In previous post, we have seen jackson example, but it reads whole json file in memory but if we have large json file, then it is not efficient. So If you want to read or write large json file, we need to use jackson streaming API which do not read whole file in memory.
Two important classes for jackson streaming API are:
  • JsonGenerator : To write json
  • JsonParser : To read json
But Jackson streaming API is very less flexible and can not be easily used. We need to handle each and every field and there is no need to create java object unless explicitly required.


In this post,we will read and write JSON using Jackson Streaming API.
1). Create a java project named “JacksonStreamingAPIExample”

2) Add following maven dependency for jackson.
Pom.xml :

3) create a pojo named “Country.java”

Write JSON to file:

4) Create a new class named “JacksonWriteToFileStreamingAPIExample.java” in src->org.arpit.java2blog.JacksonStreamingAPIExample

Run above program and content of file countryStreaming.json will be as below :

Read JSON to file:

Here we will read above created JSON file.
5) Create a new class named “JacksonJsonReadFromFileExample.java” in src->org.arpit.java2blog.JacksonStreamingAPIExample

Run above program and you will get following output:

click to begin
20KB .zip

6) Project Structure:

3 Comments

  1. Pras October 5, 2015
    • Dave October 6, 2015
  2. lemiguelapps October 14, 2015

Add Comment