Skip to content

Instantly share code, notes, and snippets.

@HalCanary
Last active June 23, 2023 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HalCanary/1f2fa4c9952b81e19bbc3d0cbf19ad15 to your computer and use it in GitHub Desktop.
Save HalCanary/1f2fa4c9952b81e19bbc3d0cbf19ad15 to your computer and use it in GitHub Desktop.
[MacOS] get_boolean_value_from_json.sh
get_boolean_value_from_json() {
# Return true if the JSON file exists, the variable is set, and it
# evaluates as true in javascript.
test -f "$1" && osascript -l 'JavaScript' 2>&1 <<- EOF
ObjC.import('stdlib');
$.exit(JSON.parse(\`$(cat "$1")\`).${2} ? 0 : 1);
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment