/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();
}
}
}