Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58627
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <papillion@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'string.': 0.05; 'json': 0.07; 'string': 0.09; 'parameter': 0.09; 'subject:command': 0.09; 'subject:How': 0.10; 'python': 0.11; 'assume': 0.14; 'called.': 0.16; 'formatted': 0.16; 'generator.': 0.16; 'everyone,': 0.19; 'saying': 0.22; 'shell': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'helper': 0.24; 'parse': 0.24; 'looks': 0.24; 'script': 0.25; 'this:': 0.26; 'code:': 0.26; "i'm": 0.30; 'prints': 0.31; 'anyone': 0.31; 'thanks!': 0.32; 'subject:the': 0.34; 'could': 0.34; 'received:google.com': 0.35; 'skip:j 20': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'so,': 0.37; 'expected': 0.38; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; 'above,': 0.60; 'eventually': 0.60; 'tell': 0.60; 'fact,': 0.69 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=nVonuGwJgdro6l76504vc67Ydjlf/FIi8wZuLPddwCk=; b=fUaCuFROPvM0t2Ag4LiCtjkYVoHai6hWTLfBsLUuTvnIBbVkp1PHMh35chWxAS/2Y4 GMzNvT8cincrBo6GLnQm4malLffyOrXlSxkxwDgoZGKxf8Rf4N5w9G1O8KGW66J5rTse bV8/l5qKAJSF9DVdT1oPYoVIbuKchJ9Rw03CoezBhI774klcyDHEG719IMM3WmG979ii Rao1wadRfolvFryvfGLRLEuwvspiA3rUkkYhVWT9cHZ0rf6n6MWy/nFRwJvRLMTc9wKH 5CxE2Sk+aaVoHaxIumviUULXrJQDrNVVNIhiRyT1ck5xXysvtpUQc5P23BSUIsL7jcoJ GiKQ== |
| X-Received | by 10.236.84.81 with SMTP id r57mr4303512yhe.88.1383796392080; Wed, 06 Nov 2013 19:53:12 -0800 (PST) |
| Date | Wed, 06 Nov 2013 21:53:09 -0600 |
| From | Anthony Papillion <papillion@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | How to parse JSON passed on the command line? |
| X-Enigmail-Version | 1.6 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| 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.2117.1383796399.18130.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1383796399 news.xs4all.nl 15897 [2001:888:2000:d::a6]:60801 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:58627 |
Show key headers only | View raw
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"}
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}
Now, for the harder part. When I try to PARSE this JSON using this code:
json_string = json.loads(sys.argv[1])
I get an error saying that "No JSON object could be decoded". Even
though this looks like valid JSON and was generated by a JSON generator.
Can anyone tell me what I'm doing wrong? Basically, I want to eventually
get the value of url into a string.
Thanks!
anthony
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
How to parse JSON passed on the command line? Anthony Papillion <papillion@gmail.com> - 2013-11-06 21:53 -0600
Re: How to parse JSON passed on the command line? Roy Smith <roy@panix.com> - 2013-11-06 23:12 -0500
Re: How to parse JSON passed on the command line? yupeng zhang <universeroc@gmail.com> - 2013-11-06 22:09 -0800
Re: How to parse JSON passed on the command line? donarb <donarb@nwlink.com> - 2013-11-07 09:11 -0800
csiph-web