Does anyone have any sample Java code to convert a JSON document to XLS/CSV file? I have tried to search on Google but to no avail.
|
You could only convert a JSON array into a CSV file. Lets say, you have a JSON like the following :
Lets see the code for converting it to csv :
Now you got the CSV generated from JSON. It should look like this:
The maven dependency was like,
|
||||
|
you can use commons csv to convert into CSV format. or use POI to convert into xls. if you need helper to convert into xls, you can use jxls, it can convert java bean (or list) into excel with expression language. Basically, the json doc maybe is a json array, right? so it will be same. the result will be list, and you just write the property that you want to display in excel format that will be read by jxls. See http://jxls.sourceforge.net/reference/collections.html If the problem is the json can't be read in the jxls excel property, just serialize it into collection of java bean first. |
|||||
|
A JSON document basically consists of lists and dictionaries. There is no obvious way to map such a datastructure on a two-dimensional table. |
|||
|