Read Big Decimal In JSON

Updated: May 31, 2022

This example shows you how to read big decimals form JSON file using Data Pipeline.

In this demo code you are going to use JsonRecordReader to read records which contains country, capital, language and XY coordinate fields from simple-json-to-file-with-bigdecimal.json file and print them on the console via StreamWriter.newSystemOutWriter().

BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale.

Input JSON file

    ,"x-coodrinates" : 14.583331
    ,"y-coodrinates" : 121.0
    ,"x-coodrinates" : 35.652832
    ,"y-coodrinates" : 139.839478

Java Code Listing

package com.northconcepts.datapipeline.examples.cookbook;


import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.DataWriter;
import com.northconcepts.datapipeline.core.StreamWriter;
import com.northconcepts.datapipeline.job.Job;
import com.northconcepts.datapipeline.json.JsonRecordReader;

public class ReadBigDecimalInJSON {

    public static void main(String[] args) {
        DataReader reader = new JsonRecordReader(new File("example/data/input/simple-json-to-file-with-bigdecimal.json"))
        DataWriter writer = StreamWriter.newSystemOutWriter();
       , writer);

Code Walkthrough

  1. First, JsonRecordReader is created corresponding to the input JSON file simple-json-to-file-with-bigdecimal.json. By passing true to setUseBigDecimal() method you are enabling JsonRecordReader to use BigDecimal which is disabled by default. In this example JsonRecordReader is enabled to read XY coordinate values from the input JSON file as big decimals.
  2. Data are transferred from JsonRecordReader to the console via method. See how to compile and run data pipeline jobs


JsonRecordReader is an input reader that can read records from an input JSON stream. A method JsonRecordReader.addRecordBreak tells the reader to return a new record using whatever fields have been assigned. This method is basically used to demarcate records.

Console output

04:09:46,407 DEBUG [main] datapipeline:37 - DataPipeline v7.2.0-SNAPSHOT by North Concepts Inc.
04:09:52,630 DEBUG [main] datapipeline:615 - Job[1,job-1,Wed May 25 04:09:52 EAT 2022]::Start
0 - Record (MODIFIED) {

1 - Record (MODIFIED) {

2 records
04:10:00,157 DEBUG [main] datapipeline:661 - job::Success
Mobile Analytics