Created
February 21, 2018 18:35
-
-
Save yarreg/eee0b218ecde60688a7ac84c74d15fbb to your computer and use it in GitHub Desktop.
Get/Set JSON key value
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/sh | |
set_json_val() { | |
sed -e 's!^\(\s*"'"$2"'"\s*:\s*"\?\)[^,"]*!\1'"$3"'!' -i $1 | |
} | |
get_json_val() { | |
sed -e 's!\([^\\]\)"!\1!g' -e 's!,$!!' $1 | \ | |
sed -n "s!.*${2}: *\(.*\)!\1!p" | |
} | |
echo $(get_json_val file.json key_name) | |
set_json_val file.json key_name key_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment