I'd like to pass a simple set of name/value pairs to a python script via json on the command line.
$ curl -s https://jsonplaceholder.typicode.com/posts/1 | python3.6 -c 'import sys, json; print json.load(sys.stdin)'
File "<string>", line 1
import sys, json; print json.load(sys.stdin)
^
SyntaxError: invalid syntax
(23) Failed writing body
The json is simple:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat",
"body": "quia et suscipit\nsuscipit..."
}
And the goal is to assign variables like:
if json.load(sys.stdin)["title"] is not None:
post_title = json.load(sys.stdin)["title"]
How can I accomplish this correctly?