{"Account":"789","Date":"2013-07-31","Unique Id":"2013073101","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-30T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073005","Tran Type":"TFR IN","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073004","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073003","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073002","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-160","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073001","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"160","formatedDate":"2013-07-29T12:00:00.000Z"}
This is the output of the dimension of crossfilter.js with dc.js, I want to sent this string to a java program to convert this to json object, then I want to read the data and extract some data. Sent string in json format back to client side.
This is how to create the output
var dimData = accountDim.top(Infinity);
var dddata = [];
dimData.forEach(function (x) {
console.log(JSON.stringify(x));
dddata.push(JSON.stringify(x));
});
$.get(window.location.href + "toJSON?files=" + dddata.join(), function (){});
My JAVA program:
public static void main(String[] args) throws IOException, ParseException {
JSONParser parser = new JSONParser();
JSONObject jsons = (JSONObject) parser.parse(args[0]);
PrintWriter writer = new PrintWriter("res.json", "UTF-8");
writer.println(jsons);
writer.close();
}
This is my http server in node.js
var express = require('express');
var app = express();
app.use('/JS',express.static(__dirname + '/JS'));
app.use('/CSS',express.static(__dirname + '/CSS'));
app.use('/', express.static(__dirname + '/'));
app.get('/', function (req, res) {
// res.sendFile("/index.html");
}).listen(8080);
app.get('/toJSON', function(req, res, next) {
process.stdout.write('Extracting data to JSON...... ');
var files = req.query.files;
var spawn = require('child_process').spawn;
var child = spawn('java', ['-cp', 'Jarfile/CSVExtractor.jar:.', 'toJSON.ToJSON', files]);
process.stdout.write("done.\n");
child.stderr.on('data', function (data) {
process.stderr.write(data);
}).on('end', function() {
res.end();
});
child.stdout.on('data', function (data) {
res.write(data);
}).on('end', function() {
res.end();
});
});
My question is are there any better way to sent the dimension data to java via node.js, if not, how can I convert the string to json like this, then retrieve the data?
Can anybody help me? Any help would be appreciated.