Skip to content

Instantly share code, notes, and snippets.

@edasque
Last active Dec 22, 2020
Embed
What would you like to do?
pre-commit Git hook to JSONlint - place it in .git/hooks
#!/bin/sh
git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB |
xargs -0 -t -L1 /usr/local/bin/jsonlint -c;
if [ "$?" != "0" ]; then
echo "\nOne or more JSON file didn't pass jsonlint'ing.";
echo "Fix them before committing. If it is not possible to fix them all commit with the option --no-verify.";
exit 1;
fi
@edasque
Copy link
Author

edasque commented Feb 19, 2016

This works on a mac. xargs is a little bit different on linux where it probably should be changed to xargs --null --no-run-if-empty /usr/local/bin/jsonlint -c;.
This assumes jsonlint 1.6.x is installed in /usr/local/bin

@v6
Copy link

v6 commented May 8, 2017

// , Nice work. This was the third result in my search for jsonlint hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment