couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Stanford <cl...@may.be>
Subject Use of json2.js in HEAD
Date Tue, 09 Feb 2010 09:43:34 GMT
I'm a little confused about the JSON object and the toJSON() function
in shows and lists.

In 0.10 I could have a show which did this:

function(doc, req)
{
   return { body : JSON.stringify(doc, null, 2) }
}

and get a nicely formatted output.  In HEAD, I get:

{"error":"render_error","reason":"function raised error: (new 
ReferenceError(\"JSON is not defined\", \"\", 4)) \nstacktrace: ([object 
Object],[object Object])@:4\napply([object Object],[object 
Array])@:0\nrunShow(function (doc, req) {var d = new Array(1, 2, 3, 
4);return {body:JSON.stringify(doc['null'], 2)};},[object 
Object],[object 
Array])@/usr/local/share/couchdb/server/main.js:882\n(function (doc, 
req) {var d = new Array(1, 2, 3, 4);return 
{body:JSON.stringify(doc['null'], 2)};},[object Object],[object 
Array])@/usr/local/share/couchdb/server/main.js:985\napply(null,[object 
Array])@:0\n(\"_design/main\",[object Array],[object 
Array])@/usr/local/share/couchdb/server/main.js:1343\napply(null,[object 
Array])@:0\n()@/usr/local/share/couchdb/server/main.js:1385\n@/usr/local/share/couchdb/server/main.js:1396\n"}

In HEAD, if I replace the JSON.stringify() with toJSON(doc), it mostly 
gives me an unformatted version of the document.

Strings, numbers, arrays and objects seem to work OK with toJSON() however:

function (doc, req)
{
   var d = new Date();
   return { body : toJSON(d) }
}

returns {}

So it seems that the JSON object has disappeared and toJSON() is broken 
for dates.

Or am I misunderstanding what should happen?

Regards,
Cliff.

-- 
Cliff Stanford
Might Limited                           +44 845 0045 666 (Office)
Suite 67, Dorset House                  +44 7973 616 666 (Mobile)
Duke Street, Chelmsford, CM1 1TB


Mime
View raw message