Could anyone give me a clue what is wrong with the JSON syntax listed below. According to JsonLint the error is/begins in front of the word "csv"
. I cannot see the error in the syntax but it must be there. If someone could just tell me the principle behind my error please.
{
"lists": {
"csv": "function(head, req) {
var row,
first = true;
// output HTTP headers
start({
headers: {
'Content-Type': 'text/csv'
},
});
// iterate through the result set
while (row = getRow()) {
// get the doc (include_docs=true)
var doc = row.doc;
// if this is the first row
if (first) {
// output column headers
send(Object.keys(doc).join(',') + 'n');
first = false;
}
// build up a line of output
var line = '';
// iterate through each row
for (var i in doc) {
// comma separator
if (line.length > 0) {
line += ',';
}
// output the value, ensuring values that themselves
// contain commas are enclosed in double quotes
var val = doc[i];
if (typeof val == 'string' && val.indexOf(',') > -1) {
line += '" ' + val.replace(/"/g, ' "" ') + ' "';
} else {
line += val;
}
}
line += 'n';
// send the line
send(line);
}
}
"
}
}
EDIT:
Full code(CouchDB view/list):
{
"_id": "_design/comptno",
"_rev": "2-4531ba9fd5bcd6b7fbc5bc8555f0bfe3",
"views": {
"list_example": {
"map": "function(doc) {\r\n if (doc.compartment.number) {\r\n emit(doc.compartment.number, null);\r\n }\r\n};"
},
"list_example2": {
"map": "function(doc) {\r\n if (doc.compartment.number) {\r\n emit(doc.compartment.number, null);\r\n }\r\n};"
}
},
"lists":{"csv":"function(head, req) { var row, first = true; // output HTTP headers start({ headers: { 'Content-Type': 'text/csv' }, }); // iterate through the result set while (row = getRow()) { // get the doc (include_docs=true) var doc = row.doc; // if this is the first row if (first) { // output column headers send(Object.keys(doc).join(',') + 'n'); first = false; } // build up a line of output var line = ''; // iterate through each row for (var i in doc) { // comma separator if (line.length > 0) { line += ','; } // output the value, ensuring values that themselves // contain commas are enclosed in double quotes var val = doc[i]; if (typeof val == 'string' && val.indexOf(',') > -1) { line += '"' + val.replace(/"/g, '""') + '"'; } else { line += val; } } line += 'n'; // send the line send(line); }}"},
"language": "javascript"
}