-
-
Save chefren/9a2711e86ef54b19b082f3892eafcda0 to your computer and use it in GitHub Desktop.
git pre-commit hook to validate json objects so you don't commit broken json.
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
#!/usr/bin/env bash | |
# Runs all .json files through pythons json lint tool before commiting, | |
# to make sure that you don't commit broken json objects. | |
git_dir=$(git rev-parse --show-toplevel) | |
for file in $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- \ | |
| grep -P '\.(json)$'); do | |
python -mjson.tool $file 2> /dev/null | |
if [ $? -ne 0 ] ; then | |
echo "Lint check of JSON object failed. Your changes were not commited." | |
echo "in $git_dir/$file:" | |
python -mjson.tool $file | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment