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 19:46:09 GMT
We're going to be creating some custom views/functions and calling them from erlang modules.
To this end, I'm just calling a function on the design document that we've created. 

Since I'm new to erlang/couch I'm just testing a very simple function being called from an
erlang module via a handler and daemon. This is based on a process that we used to bulk load
data during a conversion. 

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)


[error] [<0.278.0>] Uncaught error in HTTP request: {exit,
                                 {json_encode,
                                  {bad_term,{<<"fld">>,<<"data">>}}}}
[debug] [<0.278.0>] Stacktrace: [{mochijson2,json_encode,2},
             {mochijson2,'-json_encode_array/2-fun-0-',3},
             {lists,foldl,3},
             {mochijson2,json_encode_array,2},
             {couch_httpd,send_json,4},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request,4},
             {mochiweb_http,headers,5}]
[debug] [<0.278.0>] httpd 500 error response:
 {"error":"json_encode","reason":"{bad_term,{<<\"fld\">>,<<\"data\">>}}"}


Running that {\"fld\":\"data\"} json document thru mochijson2.decode returns
{[{<<\"fld\">>,<<\"data\">>}]} so my thought is that I need to convert
the document returned from couch function into a similar format.

Perhapos there's something else format-wise that the _views functions do when returning data?

Thanks




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

Michael,

Are you working in Erlang with something? If so, could you paste a
short snippet of what you're trying to accomplish?

Paul Davis

On Mon, Aug 31, 2009 at 2:01 PM, Michael McCaffrey<mmccaffrey@ittvis.com> wrote:
> Hello,
>
>
>
> I'm trying to get a couchdb function to return a simple json doc and I
> can't get it to validate thru mochijson2.encoder.
>
>
>
> Just trying to return {"fld","data"} and get the
> {"error":"json_encode","reason":"{bad_term,{<<\"fld\">>,<<\"data\">>}}"}
> error
>
>
>
> Running the encoder I see it expects {[{"fld","data"}]}  format which I
> cannot get the couchdb function to produce.
>
>
>
> Any help on how to format this list of json docs in a couchdb function?
>
>
>
> Thanks
>
>
>
>
>
>
>
>
>
>

Mime
View raw message