jsonlint: Validate and Format JSON in CI
jsonlint -q file.json validates that a file is well-formed JSON and exits non-zero with a parse error if not.
jsonlint is a small CLI that checks JSON syntax (and optionally formatting). It is the quickest gate to keep malformed JSON config out of a build.
What it does
jsonlint (the node jsonlint package) parses a JSON file and reports the first syntax error with a line and position. -q quiets the echo of valid input, -c enforces a compact form, and -i rewrites the file in place with consistent indentation. It exits non-zero on a parse error.
Common usage
npm i -g jsonlint
# validate quietly (no echo), fail on bad JSON
jsonlint -q config.json
# validate every JSON file
find . -name '*.json' -exec jsonlint -q {} +
# pretty-print / reformat in place
jsonlint -i config.jsonOptions
| Flag | What it does |
|---|---|
| -q, --quiet | Do not echo the parsed input |
| -c, --compact | Compact the output (no extra whitespace) |
| -i, --in-place | Reformat the file in place |
| -s, --sort-keys | Sort object keys in the output |
| -t, --indent <n> | Indentation string/width for output |
In CI
Run jsonlint -q over your JSON config in a lint job; a parse error exits non-zero and fails the build, so a stray trailing comma never reaches a deploy. For structure (not just syntax), follow it with a schema check via ajv-cli or check-jsonschema.
Common errors in CI
Parse error on line 4: ..., "port": ,--^ Expecting 'STRING', 'NUMBER', ... got 'undefined' marks the exact spot of a syntax error (often a trailing comma or missing value). Error: ENOENT: no such file or directory means a wrong path. command not found: jsonlint means it is not installed; npm i -g jsonlint. Note plain jsonlint rejects JSON5/comments, so a .jsonc file will fail.