responsecas.blogg.se

Convert csv to json
Convert csv to json









convert csv to json convert csv to json

String jsonScript = "constant header of json content" JsonFile = new BufferedWriter(new FileWriter("converted.txt"))

convert csv to json

import java.io.BufferedReader ĬsvFile = new BufferedReader(new FileReader("DataTextCsv.csv")) See the following, you had your close methods in the wrong location. I'm conscious that it would be simpler to use more specific libraries, but as I'm new with Java, I wasn't able to find the right package to download and install The application can correctly read the first line of the csv file but can not continue till the end and I continuously get this error (even if I try to set all my csv data in one line: Exception in thread "main" java.io.IOException: Stream closedĪt java.io.BufferedReader.ensureOpen(Unknown Source)Īt java.io.BufferedReader.readLine(Unknown Source)Īt CSVConverter.main(CSVConverter.java:17) JsonScript=jsonScript.substring(0,jsonScript.length()-2) String jsonScript="constant header of json content" Here is a portion of my code: BufferedReader csvFile= new BufferedReader(new FileReader("DataTextCsv.csv")) īufferedWriter jsonFile=new BufferedWriter(new FileWriter("converted.txt")) I chose to simplify by using a classic method with BufferedReader and BufferedWriter. I have the naming of the fields static here, but you could use code to set the headers dynamically: for(var j=0 jthe my code you can pass everything into a textfield directly from Excel and then use that to create a json. Excel will remove the seperators like, and others and will insert newlines etc. This way you can use a CSV that is copied into Excel. I have a similar answer like but my code can be used in conjunction with Excel directly (copy and paste from Excel into a textarea). I think, I have a better solution, this also have one issue i.e.











Convert csv to json