Created
April 3, 2019 07:07
-
-
Save khoatran/b60cd53f8dffc592f2240efcba831d59 to your computer and use it in GitHub Desktop.
Bash parse JSON key
This file contains hidden or 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 jsonValue() { | |
KEY=$1 | |
num=$2 | |
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p | |
} | |
KEY_TO_PARSE=$(curl -s -X GET "JSON_URL" | jsonValue KEY_TO_PARSE 1) | |
echo $KEY_TO_PARSE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment