Created
June 26, 2011 17:42
-
Star
(212)
You must be signed in to star a gist -
Fork
(47)
You must be signed in to fork a gist
-
-
Save cjus/1047794 to your computer and use it in GitHub Desktop.
Extract a JSON value from a BASH script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function jsonval { | |
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop` | |
echo ${temp##*|} | |
} | |
json=`curl -s -X GET http://twitter.com/users/show/$1.json` | |
prop='profile_image_url' | |
picurl=`jsonval` | |
`curl -s -X GET $picurl -o $1.png` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given this JSON in
data.json
:And I want to extract value "blue" from JSON property
color
in Windows git bash (no jq dependency), here's how I do it in a pinch:Another way to do it:
https://raymii.org/s/snippets/Get_json_value_with_sed.html