Printing json data in a formatted way

This post explains how to print json data in a properly formatted way, whether the destination is console, file etc. For example when the below code prints the json data to a file, the output will be as shown below Initial Code package package11; import java.io.File; import java.io.FileWriter; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; public… Continue reading Printing json data in a formatted way

Getting JsonGenerator settings

This post explains how to get JsonGenerator settings. JsonGenerator class obtained from JsonFactory is responsible for writing json data as a stream instead of constructing an entire object model in memory and then writing to destination. The list of settings that can be turned on or off are present in an enumeration JsonGenerator.Feature. The below… Continue reading Getting JsonGenerator settings

Writing json data using Jackson JsonGenerator

The below post explains how to write json data to file using JsonGenerator. JsonGenerator writes the data to a file in streaming way, helping the developer using the api to avoid creating an object representation of the data. We can get an instance of JsonGenerator with the help of an instance of JsonFactory as shown… Continue reading Writing json data using Jackson JsonGenerator

Retrieving JsonParser Settings

This post explains how to get json parser default settings. import java.io.File; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser.Feature; public class ProcessingDemo2 { public static void main(String[] args) throws JsonParseException, IOException { File file = new File(“jsondata.json”); JsonFactory jsonFactory = new JsonFactory(); JsonParser jsonParser = jsonFactory.createParser(file); for(Feature feature : Feature.values()) { System.out.println(feature.name()… Continue reading Retrieving JsonParser Settings

Streaming two json files in an order using JsonParserSequence

This post explains how to stream two files in a particular order Main Class import java.io.File; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.util.JsonParserSequence; public class ProcessingDemo3 { public static void main(String[] args) throws JsonParseException, IOException { File file1 = new File(“jsondata.json”); File file2 = new File(“jsondata1.json”); JsonFactory jsonFactory = new… Continue reading Streaming two json files in an order using JsonParserSequence

Reading JSON in a streaming way

This post explain how to stream a json file. We need to create an instance of JsonFactory, as shown below JsonFactory jsonFactory = new JsonFactory(); by which we can create a parser instance (i.e., JsonParser) to read the json file, as shown below JsonParser jsonParser = jsonFactory.createParser(file); Each element whether start and end of the… Continue reading Reading JSON in a streaming way