jsonlint
jsonlint is a comprehensive JSON validation tool that provides command-line interface for ensuring JSON files conform to specifications and maintain proper structure. It serves as the essential validator for JSON data integrity across web applications, APIs, and configuration systems.
Key Features:
- Pure JavaScript Implementation: Native JavaScript JSON parser ensuring accurate validation without external dependencies
- Strict JSON Compliance: Validates against official JSON specification to ensure maximum compatibility
- Syntax Error Detection: Identifies malformed JSON structures, missing brackets, invalid characters, and formatting issues
- Fast Validation: High-performance parsing suitable for large JSON files and batch processing
- Detailed Error Reporting: Clear error messages with line and column information for easy debugging
- Configurable Options: Flexible validation options through .jsonlintrc configuration files
- Batch Processing: Efficient validation of multiple JSON files in a single command
- Cross-Platform: Consistent validation behavior across Windows, macOS, and Linux environments
jsonlint documentation
- Version in MegaLinter: 16.0.0
- Visit Official Web Site
- See How to configure jsonlint rules
- See Index of problems detected by jsonlint
Configuration in MegaLinter
- Enable jsonlint by adding
JSON_JSONLINT
in ENABLE_LINTERS variable - Disable jsonlint by adding
JSON_JSONLINT
in DISABLE_LINTERS variable
Variable | Description | Default value |
---|---|---|
JSON_JSONLINT_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
JSON_JSONLINT_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
JSON_JSONLINT_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
JSON_JSONLINT_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
JSON_JSONLINT_CLI_LINT_MODE | Override default CLI lint mode - file : Calls the linter for each file- list_of_files : Call the linter with the list of files as argument- project : Call the linter from the root of the project |
list_of_files |
JSON_JSONLINT_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".json"] |
JSON_JSONLINT_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
Include every file |
JSON_JSONLINT_PRE_COMMANDS | List of bash commands to run before the linter | None |
JSON_JSONLINT_POST_COMMANDS | List of bash commands to run after the linter | None |
JSON_JSONLINT_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling JSON_JSONLINT and its pre/post commands | None |
JSON_JSONLINT_CONFIG_FILE | jsonlint configuration file nameUse LINTER_DEFAULT to let the linter find it |
.jsonlintrc |
JSON_JSONLINT_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
JSON_JSONLINT_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
JSON_JSONLINT_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
JSON_JSONLINT_CLI_EXECUTABLE | Override CLI executable | ['jsonlint'] |
MegaLinter Flavors
This linter is available in the following flavors
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 127 | |
c_cpp | Optimized for pure C/C++ projects | 57 | ||
ci_light | Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML | 22 | ||
cupcake | MegaLinter for the most commonly used languages | 88 | ||
documentation | MegaLinter for documentation projects | 50 | ||
dotnet | Optimized for C, C++, C# or VB based projects | 65 | ||
dotnetweb | Optimized for C, C++, C# or VB based projects with JS/TS | 74 | ||
go | Optimized for GO based projects | 52 | ||
java | Optimized for JAVA based projects | 55 | ||
javascript | Optimized for JAVASCRIPT or TYPESCRIPT based projects | 60 | ||
php | Optimized for PHP based projects | 55 | ||
python | Optimized for PYTHON based projects | 66 | ||
ruby | Optimized for RUBY based projects | 51 | ||
rust | Optimized for RUST based projects | 51 | ||
salesforce | Optimized for Salesforce based projects | 55 | ||
swift | Optimized for SWIFT based projects | 51 | ||
terraform | Optimized for TERRAFORM based projects | 55 |
Behind the scenes
How are identified applicable files
- File extensions:
.json
How the linting is performed
- jsonlint is called once with the list of files as arguments (
list_of_files
CLI lint mode)
Example calls
jsonlint myfile1.json myfile2.json
Help content
JSON/CJSON/JSON5 parser, syntax and schema validator and pretty-printer.
Usage: jsonlint [options] [--] [<file, directory, pattern> ...]
Options:
-f, --config <file> read options from a custom configuration file
-F, --no-config disable searching for configuration files
--ignore-proto-key ignore occurrences of "__proto__" object key
--ignore-prototype-keys ignore all keys from "Object.prototype"
-s, --sort-keys sort object keys (not when prettifying)
--sort-keys-ignore-case sort object keys ignoring the letter case
--sort-keys-locale <id> locale identifier to sort object keys with
(or "default" for the system default)
--sort-keys-case-first <id> order if only letter case is different
("upper", "lower" and "false" are allowed)
--sort-keys-numeric sort by numbers recognised in object keys
-E, --extensions <ext...> file extensions to process for directory walk
(default: json, JSON)
-i, --in-place overwrite the input files
-j, --diff print difference instead of writing the output
-k, --check check that the input is equal to the output
-t, --indent <num|char> number of spaces or specific characters to use
for indentation or a string with whitespace
-c, --compact compact error display
-M, --mode <mode> set other parsing flags according to the format
of the input data (default: json)
-B, --bom ignore the leading UTF-8 byte-order mark
-C, --comments recognize and ignore JavaScript-style comments
-S, --single-quoted-strings support single quotes as string delimiters
-T, --trailing-commas ignore trailing commas in objects and arrays
-D, --no-duplicate-keys report duplicate object keys as an error
-V, --validate <file...> JSON Schema file(s) to use for validation
-e, --environment <env> which version of JSON Schema the validation
should use
-x, --context <num> line number used as the diff context
(default: 3)
-l, --log-files print only the parsed file names to stdout
-q, --quiet do not print the parsed json to stdout
-n, --continue continue with other files if an error occurs
-p, --pretty-print prettify the input instead of stringifying
the parsed object
-P, --pretty-print-invalid force pretty-printing even for invalid input
-r, --trailing-newline ensure a line break at the end of the output
-R, --no-trailing-newline ensure no line break at the end of the output
--prune-comments omit comments from the prettified output
--strip-object-keys strip quotes from object keys if possible
--enforce-double-quotes surrounds all strings with double quotes
--enforce-single-quotes surrounds all strings with single quotes
--trim-trailing-commas omit trailing commas from objects and arrays
--succeed-with-no-files succeed (exit code 0) if no files were found
-v, --version output the version number
-h, --help display help for command
Examples:
$ jsonlint myfile.json
$ jsonlint --in-place --pretty-print mydir
$ jsonlint --comments --trailing-commas --no-duplicate-keys \
--log-files --compact --continue '**/*.json' '!**/node_modules'
Installation on mega-linter Docker image
- Dockerfile commands :
# renovate: datasource=npm depName=@prantlf/jsonlint
ARG NPM_PRANTLF_JSONLINT_VERSION=16.0.0
- NPM packages (node.js):