Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active August 29, 2015 14:01
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 tkuchiki/1f2569d56a2d5818919d to your computer and use it in GitHub Desktop.
Save tkuchiki/1f2569d56a2d5818919d to your computer and use it in GitHub Desktop.
jsonlint で json の syntax check を行う
#!/bin/bash
if [ $# -eq 0 ]; then
echo -e "\nUsage: $(basename $0) DIR [DIR ...]\n"
echo -e " json syntax checker(require jsonlint)\n"
exit 1
fi
if type jsonlint > /dev/null 2>&1 && [ $? -ne 0 ]; then
echo "jsonlint is required. [npm install -g jsonlint]"
exit 1
fi
WHITE='\033[0m'
GREEN='\033[32m'
RED='\033[31m'
OK_CNT=0
ERR_CNT=0
for DIR in "$@"; do
for _DIR in $(find $DIR -type f); do
FILENAME=$(basename $_DIR)
[ ${FILENAME##*.} != "json" ] && continue
echo "## ${_DIR}"
jsonlint -q $_DIR
if [ $? -eq 0 ]; then
echo -e "${GREEN}syntax ok${WHITE}"
OK_CNT=$((1 + $OK_CNT))
else
echo -e "${RED}syntax error${WHITE}"
ERR_CNT=$((1 + $ERR_CNT))
fi
done
done
echo
echo -e "${GREEN}ok: ${OK_CNT}${WHITE}"
echo -e "${RED}error: ${ERR_CNT}${WHITE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment