Learnt a lot from previous posts, but I am still stuck by how to have a json format output. So I am trying to parse the log and have a json format output.

The log looks like:

2014-02-25T01:00:44+0000,v=5,sv=1,ss=active,es=-,ai=e6e32a23-369b-4da3-b2da-630aee75f8c5,ip='99.114.39',rm=GET,rv=HTTP/1.1,rs=200,rt=0.787020,ru='/tag/febe1?l=http%3A%2F%2Fwww.michaels.com%2Fvideosoking',rr='http://www.michaels.com/?fdid=videos-scrapbooking',ua='Mozilla/5.0'

The log after parse is like:

2014-02-25T01:00:44+0000,
v=5,
sv=1,
ss=active,
es=-,
ai=e6e32a23-369b-4da3-b2da-630aee75f8c5,
ip='99.114...


But I want this output in json format, I am quite new in js, and not sure where should I start/fix my code, my code is following:

<!doctype html>
<html>
<head>
<title>reading file</title>
<script>
function readText(obj){
var file = obj.files[0],
div=document.getElementById('main');
if(file){
div.innerHTML='';
var reader = new FileReader();
reader.onerror = function(event){
div.innerHTML='The file can\'t be read! Error ' + event.target.error.code;
}
reader.onload = function(event){
var log = event.target.result.split("\n");
for(var i=0; i<log.length; i++){
var str = log[i].split(',');
div.innerHTML+='EventTime='+str[0]+'<br />';
for (var j=0; j<str.length; j++) {
var name = str[j].split('=');
if (name[0]=="ci"||name[0]=='si'||name[0]=='ip') {
div.innerHTML+=str[j]+'<br />';
}else {
continue;
}
}
div.innerHTML+='<br />';

}
}
reader.readAsText(file);
}
}

window.onload=function(){
document.getElementById('ff').onchange=function(){readText(this);}
}

</script>
</head>
<body>
<input type="file" id="ff" />
<div id="main"></div>
</body>

</html>