Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 48202 invoked from network); 18 Dec 2010 18:52:06 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 Dec 2010 18:52:06 -0000 Received: (qmail 92373 invoked by uid 500); 18 Dec 2010 18:52:04 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 92277 invoked by uid 500); 18 Dec 2010 18:52:04 -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 92269 invoked by uid 99); 18 Dec 2010 18:52:04 -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 18:52:04 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of paul.joseph.davis@gmail.com designates 209.85.210.180 as permitted sender) Received: from [209.85.210.180] (HELO mail-iy0-f180.google.com) (209.85.210.180) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Dec 2010 18:51:58 +0000 Received: by iyi12 with SMTP id 12so1280104iyi.11 for ; Sat, 18 Dec 2010 10:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=FonmQRixCyaxoS16DME02Q88ZrxCi2kj+5AXepBG+Ik=; b=XnMUXKF7H+H1/2XGdnKG1Qof7Wie1d6jmo/bJXvnXnvIH5ZJbVhrQ5WUrMG98nIZP6 lykIVojJLubExlvD+/AfF8NY2KGsQ8PkhlWcw/uXlAMud3PkBbJeEsKptgTQ1L9HlVmX FHmOUU3zgWV4484002j+rvn5SY+DxBXR6VMkg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=am2TAmLFS+x50qKY3oQH8zUuUFQ0lLnTH1DfGj9C54+WGbRu5rVCAz2FLvT7ySF760 XlzygkuT56MZyACBL99xJJENYBru2K7ButcnD65L7pM0h2pZmRzKKPBepWAKAHrw+5JC 0BqoC1fpVS2LuaAtHLv8y5JZo1v+YdoFJedtI= Received: by 10.42.239.129 with SMTP id kw1mr2239719icb.522.1292698297675; Sat, 18 Dec 2010 10:51:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.30.72 with HTTP; Sat, 18 Dec 2010 10:50:57 -0800 (PST) In-Reply-To: References: From: Paul Davis Date: Sat, 18 Dec 2010 13:50:57 -0500 Message-ID: Subject: Re: how should I handle JSON parsing in update handler To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 updat= es > 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/94472998f519050= f3a2271888d137ed7\?field=3Dstatus\&value=3DRUNNING > > {"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 obj= ect > message? > { > =A0 "status": "function(doc, req) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0var field =3D req.query.field; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0var value =3D req.query.value; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0doc[field] =3D value; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return[doc,{"status":value}]; > =A0 =A0}", > } Pretty sure its supposed to be "return doc;" > >> On Sat, Dec 18, 2010 at 12:40 PM, Josh803316 wrot= e: >> >>> 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) { >>>> =A0 =A0 var active_test =3D JSON.parse(req.body); >>>> >>>> =A0 =A0 doc['active_test'] =3D active_test; >>>> =A0 =A0 return [doc, req.body]; >>>> =A0 =A0} >>>> >>>> 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 wha= t >>>> is the >>>> > best way to convert it to a JSON object? >>>> > >>>> > Do the CouchDb js libraries already include a built in JSON parser o= r >>>> do I >>>> > have to use eval? >>>> > >>>> > "active_test" : function(doc, req) { >>>> > =A0 =A0 =A0var active_test =3D eval('(' + req.body + ')'); >>>> > >>>> > =A0 =A0 =A0doc['active_test'] =3D active_test; >>>> > =A0 =A0 =A0return [doc, req.body]; >>>> > =A0 =A0 } >>>> > >>>> >>> >>> >> >