Created
August 30, 2021 13:26
-
-
Save lidopaglia/ca641d0ea5f82667cb654b96e417fff7 to your computer and use it in GitHub Desktop.
returns the value of a json property
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() { | |
# extract the value of a json property. | |
# if avoiding jq as dependency makes sense. | |
# https://gist.github.com/cjus/1047794 | |
prop="$1";json="$2" | |
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##*|} | |
} | |
echo "$(jsonval 'some_key' $some_json)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment