Skip to content

jsonlint

GitHub stars GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

jsonlint documentation

jsonlint - GitHub

Configuration in MegaLinter

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 files
Ex: [".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 Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 121 Docker Image Size (tag) Docker Pulls
c_cpp Optimized for pure C/C++ projects 55 Docker Image Size (tag) Docker Pulls
ci_light Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML 22 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 85 Docker Image Size (tag) Docker Pulls
documentation MegaLinter for documentation projects 51 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 64 Docker Image Size (tag) Docker Pulls
dotnetweb Optimized for C, C++, C# or VB based projects with JS/TS 73 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 53 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 55 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 60 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 54 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 62 Docker Image Size (tag) Docker Pulls
ruby Optimized for RUBY based projects 51 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 51 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 55 Docker Image Size (tag) Docker Pulls
swift Optimized for SWIFT based projects 51 Docker Image Size (tag) Docker Pulls
terraform Optimized for TERRAFORM based projects 55 Docker Image Size (tag) Docker Pulls

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
  -s, --sort-keys              sort object keys (not when prettifying)
  -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
  -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