JSONLint CLI
jsonlint-cli is a command-line interface wrapper for the underlying jsonlint library, designed to enhance JSON validation workflows beyond the basic functionality offered by jsonlint itself. While it leverages jsonlint for core JSON validity checking and local schema validation, this CLI tool significantly expands capabilities. Key differentiators include support for glob expansion to lint multiple files (e.g., `**/*.json`), remote JSON schema validation, and adherence to JSON Schema Draft-04. It also introduces an eslint-style configuration system through `.jsonlintrc` and `.jsonlintignore` files for project-specific settings and file exclusions. The package's current stable version is 1.0.1, released in March 2016. Its release cadence is effectively dormant, indicating it is no longer actively maintained or developed.
Common errors
-
command not found: jsonlint-cli
cause The jsonlint-cli package was not installed globally or is not in your system's PATH.fixRun `npm install -g jsonlint-cli` to install the package globally, or ensure the npm global bin directory is included in your shell's PATH environment variable. -
No files specified and no input from stdin.
cause jsonlint-cli requires either file paths/globs as arguments or JSON content piped to stdin to perform validation.fixProvide a file path or glob pattern (e.g., `jsonlint-cli mydata.json` or `jsonlint-cli '**/*.json'`) or pipe content (e.g., `echo '{"key":"value"}' | jsonlint-cli`). -
JSON parsing error: Unexpected token ...
cause The input JSON is syntactically invalid, causing the underlying jsonlint parser to fail.fixReview the JSON file or input string for syntax errors such as missing commas, unclosed brackets, or incorrect string escaping. Tools like VS Code's built-in JSON validator can help identify issues.
Warnings
- breaking The `--quiet` flag was removed in version 1.0.0. Errors are now always printed to stderr regardless of other options.
- gotcha This package has been abandoned since March 2016, with no further releases or active development. It may contain unpatched security vulnerabilities or compatibility issues with newer Node.js versions or JSON Schema drafts.
- gotcha Configuration precedence for `.jsonlintrc` and `.jsonlintignore` files might be less intuitive in complex directory structures, potentially leading to ignored files being linted or valid files being excluded. While a fix for precedence was implemented in v1.0.1, it's still a point to verify.
Install
-
npm install jsonlint-cli -
yarn add jsonlint-cli -
pnpm add jsonlint-cli
Imports
- jsonlint-cli (command)
npm install -g jsonlint-cli # Then use the command
Quickstart
npm install -g jsonlint-cli
# Validate a single JSON file
jsonlint-cli path/to/your-config.json
# Validate multiple JSON files using glob patterns and a remote schema
jsonlint-cli --validate http://json.schemastore.org/package --ignore 'node_modules/**/*.json' '**/package.json'
# Lint JSON from stdin and pretty-print it
cat package.json | jsonlint-cli --pretty --indent 4
# Example with a .jsonlintrc config file
# content of .jsonlintrc:
# {
# "validate": "http://json.schemastore.org/package",
# "ignore": ["dist/**/*.json"],
# "indent": 2,
# "pretty": true
# }
jsonlint-cli '**/*.json'