0

/1/ { "ZZ" : 123, "CC" : { "A" : false, "D" : false }, "C" : false }

/2/ { "ZZ" : 12123, "CC" : { "A" : false, "D" : false }, "C" : false }

I'm trying to convert this file to excel in csv format but error occurs due to the presence of multiple JSONs.

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;

import com.github.opendevl.JFlat;

public class JSON2CSV {
public static void main(String myHelpers[]) throws Exception{
    String[] str;
    try {
        str = new String(Files.readAllBytes(Paths.get("D:\\My File_674335\\csvConversion\\inputJSON.json"))).split("}");
        System.out.println(Arrays.toString(str));

        for (String string : str) {


        JFlat flatMe = new JFlat(string);


        //directly write the JSON document to CSV
        //flatMe.json2Sheet().write2csv("D:\\My File_674335\\fromJSON.csv");
        flatMe.json2Sheet().headerSeparator().write2csv("D:\\My File_674335\\csvConversion\\fromJSON.csv");

        //directly write the JSON document to CSV but with delimiter
        //flatMe.json2Sheet().write2csv("/path/to/destination/file.json", '|');   
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

}

Sathish
  • 21
  • 4
  • updated my attempts – Sathish Nov 29 '18 at 07:48
  • Can you also include the complete error message that you are getting? Also, how are you inputting those 2 json? Since I only saw 1 json file being inputted – Andreas Nov 29 '18 at 07:52
  • Possible duplicate of [Parse .txt to .csv](https://stackoverflow.com/questions/22526679/parse-txt-to-csv) – Ishita Sinha Nov 29 '18 at 08:00
  • Exception in thread "main" com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 15 column 3 path $.AA_FCTR.PRI_ICD_CD at com.google.gson.internal.Streams.parse(Streams.java:58) – Sathish Nov 29 '18 at 08:34
  • Input is through inputJSON.json or a text file containing all the jsons in – Sathish Nov 29 '18 at 08:35
  • Why not read the file one line at a time into an array instead of reading the whole file? – Joakim Danielson Nov 29 '18 at 09:22

0 Answers0