res.json() not handing json array properly

4,486 views
Skip to first unread message

yo12

unread,
Mar 23, 2012, 10:29:02 AM3/23/12
to Express
If I pass an array to res.json() then it is not available to client.

res.json([{"name":"tt"},{"name":"gg"}]);

it given only {"name":"tt"} to client.

while on using json object, it is available correctly.

res.json({"obj":[{"name":"tt"},{"name":"gg"}]});

Is this a bug ? or anything workaround can be done for this,

Ryan Schmidt

unread,
Mar 23, 2012, 8:57:52 PM3/23/12
to expre...@googlegroups.com

JSON stands for "JavaScript Object Notation", so it seems logical to me that you would need to pass res.json() a JavaScript object -- not an array, not a string, not an integer, not any other type.


Lothar Pfeiler

unread,
Mar 24, 2012, 11:59:46 AM3/24/12
to Express
I don't think its a JSON problem. In JS an array is an object, too,
isn't it? Also, JSON.stringify() could deal with this example. I
haven't looked at res.json yet. Looks like I could use this function,
too. Is there a dependency to 'Content-Type'?

tjholowaychuk

unread,
Mar 24, 2012, 2:14:08 PM3/24/12
to expre...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages