Hello all,

I have a function in JS, that I need to translate in Java to be used in my JSP as part of server side script. I need to find out what's the equavalent of JSON.stringify() in Java? This is my current JS function. This functioin takes a CSV file as input, that has tab separated columns, and converts it inot JSON file. But, now the requiremnet is that the CSV files are located on the server, and I can't use JS. I need to use server side scripting to handle this request, either at my JSP level using server side script, or at my servlet level on the server side.

function handleCSV(evt) {
    var file = this.files[0];
    var output = [];
    var reader = new FileReader();
    reader.onload = function(progressEvent){
        var lines = this.result.split('\n');                   
        for(var line = 0; line < lines.length; line++){
            var arrline = lines[line].split('\t');                     
            output[line] = JSON.stringify(arrline);
        }
        document.getElementById("data").innerHTML = JSON.stringify(output);
    };
    reader.readAsText(file);
    btnGenerate.disabled = false;
}

Use jackson-dataformat-csv, it is ratther simple to map CSV and generate JSON, than send it in response to user

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.