How to use json validation as a pre-commit quality check
- Step 1Manual pre-commit check — Before git add, paste the modified JSON files here and validate each one. Fix any errors before staging. This takes 30 seconds and prevents CI failures and bad commits.
- Step 2Set up a git pre-commit hook with husky — Install husky and lint-staged: npm install --save-dev husky lint-staged. Initialize husky: npx husky init. Add .husky/pre-commit: npx lint-staged.
- Step 3Configure lint-staged for JSON validation — In package.json: { "lint-staged": { "*.json": ["python3 -m json.tool"] } }. This runs Python's json.tool on every staged JSON file — it exits with a non-zero status if the JSON is invalid, blocking the commit.
- Step 4Or use Prettier for combined format and validate — { "lint-staged": { "*.json": ["prettier --write", "prettier --check"] } }. Prettier validates JSON syntax and re-formats it to project standards in the same pre-commit step.
Frequently asked questions
What JSON validator does Node.js JSON.parse use, and is it reliable for pre-commit checks?+
Node.js JSON.parse is a strict RFC 8259 JSON parser — it correctly rejects trailing commas, comments, single-quoted strings, and non-string keys. It is reliable for pre-commit syntax validation. The only edge case to watch is Infinity and NaN, which are valid JavaScript but not valid JSON and are rejected by JSON.parse correctly.
How do I exclude large auto-generated JSON files from pre-commit validation?+
In lint-staged config, use a negation pattern: { "*.json": [...], "!dist/**/*.json": [...] }. Or configure .gitignore to exclude auto-generated JSON files from version control entirely — files not tracked by git are never staged and never processed by lint-staged.
Is the staged file content transmitted to JAD Apps?+
No. Validation runs entirely in your browser. Staged files and their content are never transmitted to JAD Apps servers.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.