incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael McCaffrey" <mmccaff...@ittvis.com>
Subject RE: valid json string for mochijson2
Date Mon, 31 Aug 2009 20:16:21 GMT
Here's the code I've stolen from the conversion process. Granted, this used to be a POST routine
that I've converted to a GET for my testing/learning purposes...


{FormResp} = csw_view_query_servers:render_view(Lang, UpFun, nil, nil, Req, Db),
couch_httpd:send_json(Req, FormResp); 


-module(csw_view_query_servers)
render_view(Lang, UpdateFun, DocId, Doc, Req, Db) ->
    Pid = get_os_process(Lang),
    {JsonReqIn} = couch_httpd_external:json_req_obj(Req, Db),

    {JsonReq, JsonDoc} = case {DocId, Doc} of
        {nil, nil} -> {{JsonReqIn}, null};
        {DocId, nil} -> {{append_docid(DocId, JsonReqIn)}, null};
        _ -> {{append_docid(DocId, JsonReqIn)}, couch_doc:to_json_obj(Doc, [revs])}
    end,

	try couch_os_process:prompt(Pid, [<<"show_doc">>, UpdateFun, JsonDoc, JsonReq])
of
        FormResp ->
            FormResp
    after
        ok = ret_os_process(Lang, Pid)
    end.


If it requires a erlJSON format, how does one produce this out of couchdb function? 

Thanks again.

-----Original Message-----
From: Paul Davis [mailto:paul.joseph.davis@gmail.com] 
Sent: Monday, August 31, 2009 2:00 PM
To: user@couchdb.apache.org
Subject: Re: valid json string for mochijson2

> So I've got a simple function that just returns a json doc.
> {
>   "getData": "function(doc){ return {\"fld\":\"data\"};}"
> }
>
> It is called from an erlang module which gets back a FormResp and then calls
>
> couch_httpd:send_json(Req, FormResp)

Can you paste this bit of Erlang that you're using? If you're using
the map docs interface, then it should be returned as a proper ErlJSON
object but its hard to guess.

Paul

Mime
View raw message