Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1421C994A for ; Tue, 4 Oct 2011 01:09:05 +0000 (UTC) Received: (qmail 97397 invoked by uid 500); 4 Oct 2011 01:09:03 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 97343 invoked by uid 500); 4 Oct 2011 01:09:03 -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 97335 invoked by uid 99); 4 Oct 2011 01:09:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2011 01:09:03 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of thomasevdv@gmail.com designates 209.85.214.52 as permitted sender) Received: from [209.85.214.52] (HELO mail-bw0-f52.google.com) (209.85.214.52) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2011 01:08:55 +0000 Received: by bke5 with SMTP id 5so8200267bke.11 for ; Mon, 03 Oct 2011 18:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=q05I1udgZn2xeD30k5e5DeKOR1f92OkYCIzLMFDVlXg=; b=pw9yzFreYo6qFWrTp/9a6aM1IGCl9lRJrBcA5vosDCY+Cc5n0ycA6OangbM0UBr/CJ dtskotG8+0VpymT/S8FuVJXh3kselDEJ9FEMDR6ZSO6h420emmmBzT0KzTXlJPP+ckH/ SNKfvYGVfqSv+ttpwj8eroALKWgbY+JxGxE1A= MIME-Version: 1.0 Received: by 10.223.20.69 with SMTP id e5mr826636fab.3.1317690514960; Mon, 03 Oct 2011 18:08:34 -0700 (PDT) Received: by 10.152.9.97 with HTTP; Mon, 3 Oct 2011 18:08:34 -0700 (PDT) Date: Mon, 3 Oct 2011 20:08:34 -0500 Message-ID: Subject: Building a JSON Show in Erlang From: Thomas Van de Velde To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=001517440f8a11709704ae6ebbc6 X-Virus-Checked: Checked by ClamAV on apache.org --001517440f8a11709704ae6ebbc6 Content-Type: text/plain; charset=ISO-8859-1 Hi, I am almost done converting an existing JavaScript show function to Erlang. Hopefully somebody can help me get over this last hump. I am trying to copy a section of my JSON document into a new JSON document. I am having trouble copying a nested structure from the document into my new document. Price below is a nested JSON structure e.g.: "price" : {"sale":20, "regular": 30}. While I can pull individual field values and explicitly set them in MyDoc, I am stuck putting everything under "price" in this structure. I'd like to avoid dealing with the pricing fields individually and simply move everything under that field into the target JSON document. Any help is greatly appreciated. Thomas fun({Doc}, {Req}) -> {Query} = couch_util:get_value(<<"query">>,Req, {[]}), Store = couch_util:get_value(<<"store">>,Query), DocId = couch_util:get_value(<<"item_id">>, Doc)," Price = couch_util:get_value(<<"price">>, Doc,{[]}), PriceCount = length(Price), MyDoc = [{"item_id", DocId}, {"store_id", Store},{"price_count",PriceCount}], % How do I add the nested price document here? Encoded = mochijson2:encode({struct, MyDoc}), {[{<<"code">>, 200}, {<<"headers">>, {[{<<"Content-Type">>, <<"text/plain">>}]}}, {<<"body">>, Encoded}]} end. --001517440f8a11709704ae6ebbc6--