Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 58432 invoked from network); 18 Dec 2010 19:09:29 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 Dec 2010 19:09:29 -0000 Received: (qmail 99664 invoked by uid 500); 18 Dec 2010 19:09:28 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 99593 invoked by uid 500); 18 Dec 2010 19:09:28 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 99585 invoked by uid 99); 18 Dec 2010 19:09:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Dec 2010 19:09:28 +0000 X-ASF-Spam-Status: No, hits=3.7 required=10.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of josh803316@gmail.com designates 209.85.214.48 as permitted sender) Received: from [209.85.214.48] (HELO mail-bw0-f48.google.com) (209.85.214.48) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Dec 2010 19:09:21 +0000 Received: by bwz8 with SMTP id 8so1609812bwz.35 for ; Sat, 18 Dec 2010 11:09:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=QSiBGa9Hg04yItwus8gbuFeA2Ij0F3s15ilcvb6N35g=; b=awT7jgvgxIhxb3Rr8+25eIlGNf0nqGytvk8m41JqNblJXT35LBtl6dixblkn5jbejN 4bKoKOqj9LyIfxnMcoo66507n53ybHdAIKXUkONmWJScJ1HzUMiXNMWtnnSrKRuT5lWq lomT91+OCWBCEJ/v2zHFDNjkrulC+BAQPj8gk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=f0HAeUN5E4eDxrZXGnpiFByu5AyCs9h6FT4RTY0HrPCNOi2OndYniNzUmHHMagfpGh 1dg0md8eQvqwZzNhg0/b/2IfVg8t50roZVkGexGE827OkxcpxV8vAGenXnOO4JsvwkuP CgRPHPzmydyzUnCyhlNSPDvIrC+FrOZdooIeU= MIME-Version: 1.0 Received: by 10.204.76.207 with SMTP id d15mr1944213bkk.104.1292699340137; Sat, 18 Dec 2010 11:09:00 -0800 (PST) Received: by 10.204.82.152 with HTTP; Sat, 18 Dec 2010 11:09:00 -0800 (PST) In-Reply-To: References: Date: Sat, 18 Dec 2010 13:09:00 -0600 Message-ID: Subject: Re: how should I handle JSON parsing in update handler From: Josh803316 To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=001636499889f867fd0497b404e1 --001636499889f867fd0497b404e1 Content-Type: text/plain; charset=ISO-8859-1 http://wiki.apache.org/couchdb/Document_Update_Handlers I see a value returned as well in the examples On Sat, Dec 18, 2010 at 12:50 PM, Paul Davis wrote: > On Sat, Dec 18, 2010 at 1:48 PM, Josh803316 wrote: > > The reason I ask is because of this, I have an update function that > updates > > the 'status' key of a document.......but when I send the request (command > > line curl) I keep getting errors on the server return. > > > > curl -X PUT > > > http://localhost:5984/workers/_design/tasc/_update/status/94472998f519050f3a2271888d137ed7\?field=status\&value=RUNNING > < > http://localhost:5984/workers/_design/tasc/_update/status/94472998f519050f3a2271888d137ed7%5C?field=status%5C&value=RUNNING > > > > > > {"error":"external_response_error","reason":"Invalid data from external > > server: {<<\"status\">>,<<\"RUNNING\">>}"} > > > > Here is my update function......do I need to JSON Encode the returned > object > > message? > > { > > "status": "function(doc, req) { > > var field = req.query.field; > > var value = req.query.value; > > doc[field] = value; > > return[doc,{"status":value}]; > > }", > > } > > Pretty sure its supposed to be "return doc;" > > > > >> On Sat, Dec 18, 2010 at 12:40 PM, Josh803316 > wrote: > >> > >>> Oops I forgot to ask how I encode as well, is it JSON.encode? > >>> > >>> > >>> On Mon, Dec 13, 2010 at 10:24 AM, Zachary Zolton < > >>> zachary.zolton@gmail.com> wrote: > >>> > >>>> You can use the global JSON object for this: > >>>> > >>>> function(doc, req) { > >>>> var active_test = JSON.parse(req.body); > >>>> > >>>> doc['active_test'] = active_test; > >>>> return [doc, req.body]; > >>>> } > >>>> > >>>> Cheers, > >>>> Zach > >>>> > >>>> On Sat, Dec 11, 2010 at 1:06 PM, Josh803316 > >>>> wrote: > >>>> > If I send a json string to my update handler as part of req.body > what > >>>> is the > >>>> > best way to convert it to a JSON object? > >>>> > > >>>> > Do the CouchDb js libraries already include a built in JSON parser > or > >>>> do I > >>>> > have to use eval? > >>>> > > >>>> > "active_test" : function(doc, req) { > >>>> > var active_test = eval('(' + req.body + ')'); > >>>> > > >>>> > doc['active_test'] = active_test; > >>>> > return [doc, req.body]; > >>>> > } > >>>> > > >>>> > >>> > >>> > >> > > > --001636499889f867fd0497b404e1--