Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.parse returns object object

Tags:

json

ajax

node.js

I am trying to get the values of item, but when I print the values in the console it displays object instead of the values. How can I access the values?

Here is my code:

var options2;
request.post(opts,function(error,response,body){
    if (!error && response.statusCode == 200 || response.statusCode == 201) {
        var jsonResponse = JSON.parse(body);
        console.log("JSON IS =" + jsonResponse.rows);
        options2 = jsonResponse.rows.reduce((acc, obj) => acc.concat(obj['Item']), []);
    }else{
        console.log(body)
    }
});

What do I miss?

like image 800
Sydnie Avatar asked Aug 30 '25 16:08

Sydnie


1 Answers

Print in a new line like:

console.log("JSON IS =");
console.log(jsonResponse.rows);

Or replace '+' with a ',' like this,

console.log("JSON IS = ", jsonResponse.rows);
like image 177
ishan shah Avatar answered Sep 02 '25 05:09

ishan shah