From 974613b780e328f38ecf5dc057af9c691867b7f8 Mon Sep 17 00:00:00 2001 From: maxogden Date: Sun, 24 Apr 2011 17:27:10 -0700 Subject: [PATCH] add simple array of json list function --- lists/json.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lists/json.js diff --git a/lists/json.js b/lists/json.js new file mode 100644 index 00000000..26416681 --- /dev/null +++ b/lists/json.js @@ -0,0 +1,28 @@ +/** + * Generates a simple array of json objects representing each doc in the db + * @author Max Ogden + */ + function(head, req) { + var row, out, sep = '\n'; + + start({"headers":{"Content-Type" : "application/json"}}); + + if ('callback' in req.query) send(req.query['callback'] + "("); + + send('['); + while (row = getRow()) { + for (var header in row.value) { + if (row.value[header]) { + var value = row.value[header]; + if (typeof(value) == "object") { + row.value[header] = "\"" + JSON.stringify(value) + "\""; + } + } + } + send(sep + JSON.stringify(row.value)); + sep = ',\n'; + } + send("]"); + if ('callback' in req.query) send(")"); + + }; \ No newline at end of file