Last active
January 27, 2023 11:49
-
-
Save rastislavcore/940ffc99d2ddb8ff555e059a3ed59e1f to your computer and use it in GitHub Desktop.
Parse Json with Bash (very simple)
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
parse_json() | |
{ | |
echo $1 | \ | |
sed -e 's/[{}]/''/g' | \ | |
sed -e 's/", "/'\",\"'/g' | \ | |
sed -e 's/" ,"/'\",\"'/g' | \ | |
sed -e 's/" , "/'\",\"'/g' | \ | |
sed -e 's/","/'\"---SEPERATOR---\"'/g' | \ | |
awk -F=':' -v RS='---SEPERATOR---' "\$1~/\"$2\"/ {print}" | \ | |
sed -e "s/\"$2\"://" | \ | |
tr -d "\n\t" | \ | |
sed -e 's/\\"/"/g' | \ | |
sed -e 's/\\\\/\\/g' | \ | |
sed -e 's/^[ \t]*//g' | \ | |
sed -e 's/^"//' -e 's/"$//' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment