Does anyone know if there is application that will let you covert preferably xls to JSON. ill also settle for a converter from csv since thats what ill probably end up having to write myself if there is nothing around.
+1
A:
See if this helps: Back to CSV - Convert CSV text to Objects; via JSON
arrocharGeek
2009-03-19 17:08:17
thanks. ill have to port this to java, but better then trying to reinvent the wheel
mkoryak
2009-03-19 17:13:10
glad it works, c# -> java is a pretty good match anyway.
arrocharGeek
2009-03-20 22:31:59
+1
A:
I just found this:
http://tamlyn.org/tools/csv2json/
( Note: you have to have your csv file available via a web address )
DanDan
2009-09-19 03:25:11
+1
A:
If you can't find an existing solution it's pretty easy to build a basic one in Java. I just wrote one for a client and it took only a couple hours including researching tools.
Apache POI will read the Excel binary. http://poi.apache.org/
JSONObject will build the JSON
After that it's just a matter of iterating through the rows in the Excel data and building a JSON structure. Here's some pseudo code for the basic usage.
FileInputStream inp = new FileInputStream( file );
Workbook workbook = WorkbookFactory.create( inp );
// Get the first Sheet.
Sheet sheet = workbook.getSheetAt( 0 );
// Start constructing JSON.
JSONObject json = new JSONObject();
// Iterate through the rows.
JSONArray rows = new JSONArray();
for ( Iterator<Row> rowsIT = sheet.rowIterator(); rowsIT.hasNext(); )
{
Row row = rowsIT.next();
JSONObject jRow = new JSONObject();
// Iterate through the cells.
JSONArray cells = new JSONArray();
for ( Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext(); )
{
Cell cell = cellsIT.next();
cells.put( cell.getStringCellValue() );
}
jRow.put( "cell", cells );
rows.put( jRow );
}
// Create the JSON.
json.put( "rows", rows );
// Get the JSON text.
return json.toString();
Matt York
2010-05-05 23:05:57