mardi 5 mai 2015

Shell Script CURL JSON value to variable

I was wondering how to parse the CURL JSON output from the server into variables.

Currently, I have -

curl -X POST -H "Content: agent-type: application/x-www-form-urlencoded" http://ift.tt/1JOP3tE -d username="$USERNAME" -d password="$PASSWORD" | python -m json.tool

But it only outputs the JSON from the server and then have it parsed, like so:

{
    "eta": "0",
    "position": "0",
    "queueToken": "6bee9e85-343f-41c7-a4d3-156f901da615",
    "success": "delayed"
}

But how do I put - for example the success value above returned from the server into a variable $SUCCESS and have the value as delayed & have queueToken as a variable $queueToken and 6bee9e85-343f-41c7-a4d3-156f901da615 as a value?



Then when I use-

echo "$SUCCESS"

it shows this as the output -

delayed



And when I use

echo "$queueToken"

and the output as

6bee9e85-343f-41c7-a4d3-156f901da615

Thanks!

Aucun commentaire:

Enregistrer un commentaire