Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58629

Re: How to parse JSON passed on the command line?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'argument': 0.05; 'json': 0.07; 'string': 0.09; 'parameter': 0.09; 'subject:command': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'assume': 0.14; 'called.': 0.16; 'formatted': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'everyone,': 0.19; 'pfxlen:0': 0.19; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'helper': 0.24; 'cc:2**0': 0.24; 'script': 0.25; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'prints': 0.31; 'probably': 0.32; 'subject:the': 0.34; 'no,': 0.35; 'received:google.com': 0.35; 'marks': 0.36; 'subject:?': 0.36; 'so,': 0.37; 'expected': 0.38; 'nov': 0.38; 'pm,': 0.38; 'little': 0.38; 'called': 0.40; 'above,': 0.60; 'gone': 0.61; 'to:addr:gmail.com': 0.65; 'fact,': 0.69; 'ate': 0.84; 'missing.': 0.84; 'sender:addr:chris': 0.84; 'quotation': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=mJU3kkOYLaUVtxfZLo4xYayz0GZgb6lXcu6mD79RQ6M=; b=VunRBGmdlUHmoNf6MBgfT1QmuXlG2HteQPvzc+LN7B+lDqcoRumrDlCQaiTBth7D3C yc6dWdLBFNtxSNgGMKLTa2QAHGm9gDgiX3VbcLcG/aFQm5v+zR/8seoONeSjYdULdvpG u/YyJXMWj38CY6shtiT+LuIZjatjK25+VfwMc=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=mJU3kkOYLaUVtxfZLo4xYayz0GZgb6lXcu6mD79RQ6M=; b=iq2moIFTkttH2vVGD0ual+Qo7spyseqd/a6fmJY6nkoAOzzbQnTX5alKEeZhfYiSwV izaTw1a0DUnEMNfyvS4WqOIadDvk2pPNtsVALLOLWwtRKlH2kjIe/HrXAFpBR2ymdhvP RVeSi/J5S4CzzTV5BDuAzhZ+nA4FJjwHivZcBAuHVo3u2Jt6fnP6MNg54HmPBz74t+Ss eFG65H3eZiTp4kZL5M0UwM0P3Lv7OR3YNHEE6vTZ/wXu7/czJVgaRapdIsIrkSqjmY+L X/6jgssWn2dA/dtmM9wCoiv0jkJSx5bqi96RQ8mK6Gj1UJ+YS0PB80Kqk6O/z2KC15xc j63A==
X-Gm-Message-State ALoCoQkVw+22qxTSXWQPoufS/jmeMeea0Y677TOyTmwKXuhv+sX6R8UlT0uXyhZDN7GA8UAo9rWV
MIME-Version 1.0
X-Received by 10.43.158.10 with SMTP id ls10mr4181603icc.20.1383797216605; Wed, 06 Nov 2013 20:06:56 -0800 (PST)
Sender chris@rebertia.com
In-Reply-To <527B0EA5.4050106@gmail.com>
References <527B0EA5.4050106@gmail.com>
Date Wed, 6 Nov 2013 20:06:56 -0800
X-Google-Sender-Auth nX4XAkR9pATIZtced0nKRF1b-yc
Subject Re: How to parse JSON passed on the command line?
From Chris Rebert <clp2@rebertia.com>
To Anthony Papillion <papillion@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc Python <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2119.1383797225.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1383797225 news.xs4all.nl 15874 [2001:888:2000:d::a6]:35846
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:58629

Show key headers only | View raw


On Wed, Nov 6, 2013 at 7:53 PM, Anthony Papillion <papillion@gmail.com> wrote:
> Hello Everyone,
>
> I'm writing a little helper script in Python that will access a JSON
> formatted argument from the shell when it's called. The parameter will
> look like this:
>
> {"url":"http://www.google.com"}
>
> So, if my program is called "getargfromcli.py" the call will look like this:
>
> getargfromcli.py {"url":"http://www.google.com"}

You probably want
    getargfromcli.py '{"url":"http://www.google.com"}'
instead, so that your string of JSON is treated literally by the shell.

> In the case above, I assume my JSON string will be argv[1]. In fact,
> when I do
>
> print sys.argv[1]
>
> It works as expected and prints out the JSON string as expected like
> this: {url:http://www.google.com}

No, that's not JSON anymore! All the required quotation marks have
gone missing. The shell ate them.

Regards,
Chris

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to parse JSON passed on the command line? Chris Rebert <clp2@rebertia.com> - 2013-11-06 20:06 -0800

csiph-web