Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 85552 invoked from network); 20 Aug 2008 18:05:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Aug 2008 18:05:20 -0000 Received: (qmail 19619 invoked by uid 500); 20 Aug 2008 18:05:18 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 19575 invoked by uid 500); 20 Aug 2008 18:05:18 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 19564 invoked by uid 99); 20 Aug 2008 18:05:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 11:05:18 -0700 X-ASF-Spam-Status: No, hits=1.0 required=10.0 tests=FB_WORD1_END_DOLLAR,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jrhuggins@gmail.com designates 64.233.170.187 as permitted sender) Received: from [64.233.170.187] (HELO rn-out-0910.google.com) (64.233.170.187) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 18:04:21 +0000 Received: by rn-out-0910.google.com with SMTP id m7so177658rnd.3 for ; Wed, 20 Aug 2008 11:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:mime-version:content-type:content-transfer-encoding :content-disposition:x-google-sender-auth; bh=MKk+mtd/nEgghS89/so2GjlgDTwe2b+bUUBabovnS4A=; b=W9Vz51ehdcTeoBgASu/ZLYhbxyMDsCx2rEnnPhgY4P4hIbzf+rYNbL0e6ChAX4vcxd tJLWSv3gKYarsiNmCCpr46zEQF3GFsthGZRJeCaxKdmNoIgKcA2srzS4I7munEfsgwTI JmmMYfJpw2mETAMb0iWsrvTPz/Ltl49oKfo3E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition:x-google-sender-auth; b=w9Oe8BfOGyE1mVoMl0mZlIu7Rxb/vNawWvql3FfYFM5AKwSc4b91MNbRo894PFuaGB QR/I9V5yHJKIBeWfo6fteTdXioofIyatgX+S3yyBK6iZ6+dzw+z7JCuff9ES6IPG6pAz goPAGx9Y0Ma2YatdYGctNA86oCONuOX7RS9wk= Received: by 10.114.153.18 with SMTP id a18mr546552wae.161.1219255489306; Wed, 20 Aug 2008 11:04:49 -0700 (PDT) Received: by 10.114.134.14 with HTTP; Wed, 20 Aug 2008 11:04:49 -0700 (PDT) Message-ID: <53b9568a0808201104h19b5e08dyd96b98d1d670144b@mail.gmail.com> Date: Wed, 20 Aug 2008 13:04:49 -0500 From: "Jason Huggins" Sender: jrhuggins@gmail.com To: couchdb-user@incubator.apache.org Subject: Appending "\n" and pretty printing output from the command line using curl (with a smidge of python) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 36a278a51616a115 X-Virus-Checked: Checked by ClamAV on apache.org Hello all! Briefly, introducing myself... and please forgive the blatant self-promotion -- I'm recently former Googler, now working on my own startup in Chicago (with some others still in San Francisco). Django and CouchDB weigh heavily in our server setup and future API... I'm *loving* CouchDB... And I've pretty much devoured every online presentation or tech talk video that exists on CouchDB so far. :-) Keep it up! With that out of the way.... I just wanted to send along a quick tip for folks using curl. If this is useful, maybe some version of this should probably graduate to a "GettingStartedWithCurl" wiki page: I'm frequently annoyed that curl doesn't end the data stream with a "\n" at the end... so a curl request usually looks like this: ---------------------------- ubuntu: ~ hugs$ curl -u http://mycouchdb {"couchdb":"Welcome","version":"0.8.0-incubating"}ubuntu: ~ hugs$ ---------------------------- I was thinking about creating a patch to add a "\n" at the end of every request, but I figured that would be a request of last resort. The stupid quick solution is append an empty "echo" command like so: -------------------------------------------------------- ubuntu: ~ hugs$ curl http://mycouchdb ; echo '' {"couchdb":"Welcome","version":"0.8.0-incubating"} ubuntu: ~ hugs$ -------------------------------------------------------- I could have stopped there... but the urge to bikeshed this further was just too great... So, I whipped up a quick python script that I now pipe to to do my "post-processing". I remembered that the GettingStartedWithPython wiki page simply does a pretty print of the content... So I heavily streamlined that script to make it play nicer with curl. So this is the result now: -------------------------------------------------------- ubuntu: ~ hugs$ curl -s http://mycouchdb | ./pprint-json { "couchdb": "Welcome", "version": "0.8.0-incubating" } ubuntu: ~ hugs$ -------------------------------------------------------- .... Ah... much better. :-) Here's the script: -------------------------------------------------------- #! /usr/bin/python import sys import simplejson raw_input = sys.stdin.read() json_data = simplejson.loads(raw_input) # Make pretty! print simplejson.dumps(json_data, sort_keys=True, indent=4) -------------------------------------------------------- To get this to work correctly, I also had to add the silent "-s" flag to curl so that it didn't print a progress meter with the results as well. (Try it without "-s" to see what I mean.) I would love it there was "pretty print all output" configuration option for Couch... but until then, I'll just use my script. :-) Cheers and thanks for all the JSON! - Jason Huggins