How to parse JSON passed on the command line?
papillion at gmail.com
Thu Nov 7 04:53:09 CET 2013
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:
So, if my program is called "getargfromcli.py" the call will look like this:
In the case above, I assume my JSON string will be argv. In fact,
when I do
It works as expected and prints out the JSON string as expected like
Now, for the harder part. When I try to PARSE this JSON using this code:
json_string = json.loads(sys.argv)
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.
More information about the Python-list