incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: View results JSON format
Date Tue, 01 Dec 2009 06:33:00 GMT
On Tue, Dec 1, 2009 at 1:25 AM, Anh <7zark7@gmail.com> wrote:
> Hi,
>
> Sorry if I've missed this in the docs, but was wondering if it's
> possible to format the output of views so that they do not always have
> this outer JSON "wrapper":
>
> {
>  "total_rows": 3,
>  "offset": 0,
>  "rows": [{
>      "id": ...,
>      ...
>    }
>  ]
> }
>
> Basically, I'd like to format view results to look like simple JSON objects:
>
> ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
>
>
> I'm doing back and forth mapping to Java objects, and the various libs
> I'm using require extra overhead (and objects) to deal with the JSON
> format I've seen in all the Couch examples.
>
>
> Thanks
>

You could accomplish this with a _list function.

Something like:

{
    "_id": "_design/foo",
    "lists": { "no_meta": "function(head, req) {
        start(200, {\"Content-Type\": \"application/json\"});
        send("[");
        started = False
        while(row = getRow()) {
            resp = started ? "," : "";
            started = True;
            resp += JSON.stringify(row);
        }
     }"}
}

HTH,
Paul Davis

Mime
View raw message