- The JSON extends to Javascript Object Notion.
- It is used for transferring data between client and server applications.
- It is used to encapsulate data in a readable and organized format.
- JSON is mostly used in REST APIs.
Now for making JSON readable in excel or csv below is the JAVA code.
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.json.*;
public class JSONtoCSV{
public static void main(String[] args) {
String JSONformat = "{\"Data\": [{\"Employee Name\": \"Tobo\",\"Work\": \"Writer\",\"Location\": \"Noida\"}]}";
JSONObject Obj1;
try {
Obj1 = new JSONObject(JSONformat);
JSONArray arr1 = Obj1.getJSONArray("Data");
File file = new File("C:\\Tobo\\EmployeeData.csv");
String table = CDL.toString(arr1);
FileUtils.writeStringToFile(file, table);
System.out.println("CSV written to "+ file);
System.out.println(csv);
}
catch(Exception e) {
System.out.println("JSON format is invalid");
e.printStackTrace();
}
}
}
O/P
CSV written to
EmpDetails.csv
Employee name,Work,Location
Tobo,Writer,Noida
Happy CODING 🙂
TOBO’s POINT
You should take part in a contest for one of the best
sites on the net. I am going to highly recommend this web site!
Great goods from you, man. I have understand
your stuff previous to and you’re just extremely excellent.
I actually like what you have acquired here, really like what you’re stating and the way in which you
say it. You make it enjoyable and you still take care of to keep it wise.
I can’t wait to read much more from you. This is really a
terrific site.
wonderful submit, very informative. I wonder why the other specialists of this
sector do not realize this. You must proceed your writing.
I am confident, you’ve a huge readers’ base already!
Good post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis.
It’s always exciting to read content from other writers and use something from their sites.