I have a JSON of the format below and I am trying to write to CSV:
{
"results": [{
"geo_position": {
"Field1": 11,
"Filed2": 12
},
"Field3": 13,
"Filed4": 14,
"Field5": 15
},
{
"geo_position": {
"Field1": 21,
"Filed2": 22
},
"Field3": 23,
"Filed4": 24,
"Filed5": 25
}
]
}
I am expecting output like:
field1,field2,field3,field4,field5
11,12,13,14,15
21,22,23,24,25
I am getting output CSV as below:
geo_position,field3,field4,field5
{Field1:11,Field2:12}, 13,14,15
{Field2:21,Field2:22},23,24,25
My java code:
JSONObject jsonObj = new JSONObject(jsonArray);
System.out.println(jsonObj);
JSONArray docs = jsonObj.getJSONArray("results");
File file=new File("C:/fromJSON2.csv");
String csv = CDL.toString(docs);
FileUtils.writeStringToFile(file, csv);
Can some one help me to figure out why I am getting in different format. What should I do to get in the format I expect?