Convert JSON to CSV

Updated: Feb 21, 2022
 * Copyright (c) 2006-2022 North Concepts Inc.  All rights reserved.
 * Proprietary and Confidential.  Use is subject to license terms.
package com.northconcepts.datapipeline.examples.cookbook;


import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.DataWriter;
import com.northconcepts.datapipeline.csv.CSVWriter;
import com.northconcepts.datapipeline.job.Job;
import com.northconcepts.datapipeline.json.JsonReader;
import com.northconcepts.datapipeline.json.SimpleJsonReader;

public class ConvertJsonToCsv {

/*   Consumes the following JSON (line breaks added for clarity).  Yes, it starts with a new line an two slashes.    

// [
      "ltt":"4:00PM EDT",
      "lt":"Aug 1, 4:00PM EDT",
      "elt":"Aug 1, 7:54PM EDT",
      "ltt":"4:00PM EDT",
      "lt":"Aug 1, 4:00PM EDT",
      "elt":"Aug 1, 7:15PM EDT",
      "ltt":"4:00PM EDT",
      "lt":"Aug 1, 4:00PM EDT",

    public static void main(String[] args) throws Throwable {

    	DataReader reader = new JsonReader(new File("example/data/input/finance.json"))
    	    .addField("symbol", "//array/object/t")
    	    .addField("exchange", "//array/object/e")
    	    .addField("price", "//array/object/l")
    	    .addField("change", "//array/object/c")

		DataWriter writer = new CSVWriter(new OutputStreamWriter(System.out));, writer);


Mobile Analytics