donald donald - 1 year ago 79
Javascript Question

Node.js: Parse JSON object

I am receiving a JSON object as :

http.get(options, function(res) {
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
var obj = JSON.parse(chunk);

BODY: [{"buck":{"email":""}}]

but now I'm not able to read anything inside it. How do I get the "email" field?


Answer Source

You should be doing something along the lines of:

http.get(options, function(res){
    var data = '';

    res.on('data', function (chunk){
        data += chunk;

        var obj = JSON.parse(data);
        console.log( );


If im not mistaken.