Hi there,

Please apologize-me if this has been discussed here before, but I try to find a good way to "jsonify" some data I have in DB.

I'm starting to code with nodejs, but I didn't find yet a good way to make some right code to do it right.

Also I need to make it correctly because I can get laaarge objet there...

Here an extract of code I have done (currently its sends an HTML table, but I want this in pure JSON only) [code simplified] :

var lSql = 'SELECT .... AND (date >= $1 AND date <= $2)) ORDER BY requests desc';
client.query(lSql, [sDate, eDate], function(err, result)
{
        response.writeHead(200, { 'Content-Type': 'text/html'});
        response.write('<h1>Test 2</h1>');
        response.write('<table>');
        
response.write('<tr><td>Type</td><td>Meaning</td><td>Requests</td></tr>');
        for (var i=0; i<result.rows.length; i++)
        {
response.write('<tr><td>' + result.rows[i].type + '</td><td>' + result.rows[i].meaning + '</td><td>' + result.rows[i].requests + '</td></tr>');
        }
        response.write('</table>');
        response.end();
        client.end();
});


I've got a nice table with Type / Meaning / Requests in a table, I would like to make this only json (ok Content-Type has to be modified into text/json, but I am stuck).

Either I do it "manualy" or I use a nice JSON stuff that seems to be inside nodejs, but I cannot figure on how to do this.

Any hints ?

Kind regards,
Xavier

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to