√
A tool to check your JSON files in CI/CD pipelines using jsonlint.
Also see: validate-json for our bash plugin to do the same thing.
This tool has been written and tested using GitHub Actions but it should work out of the box with a lot of other CI/CD tools.
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
- name: Run JSON Lint
run: bash <(curl -s https://raw.githubusercontent.com/CICDToolbox/json-lint/master/pipeline.sh)
The following environment variables can be set in order to customise the script.
Name | Purpose | Default Value |
---|---|---|
EXCLUDE_FILES | A comma separated list of files to exclude from being scanned. You can also use regex to do pattern matching. |
Unset |
REPORT_ONLY | Generate the report but do not fail the build even if an error occurred. | False |
SHOW_ERRORS | Show the actual errors instead of just which files had errors. | True |
SHOW_SKIPPED | Show which files are being skipped. | False |
You can use any combination of the above settings.
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
- name: Run JSON Lint
env:
REPORT_ONLY: true
SHOW_ERRORS: true
run: bash <(curl -s https://raw.githubusercontent.com/CICDToolbox/json-lint/master/pipeline.sh)
This is an example of the output report generated by this tool, this is the actual output from the tool running against itself.
-------------------------------------------------------------------------- Stage 1 - Parameters --
No parameters given
--------------------------------------------------------------- Stage 2 - Install Prerequisites --
[ OK ] jq is alredy installed
----------------------------------------------------------------------- Stage 3 - Run jq (v1.6) --
[ OK ] tests/data.json
------------------------------------------------------------------------------ Stage 4 - Report --
Total: 1, OK: 1, Failed: 0, Skipped: 0
---------------------------------------------------------------------------- Stage 5 - Complete --
Target files are identified using the following code:
file -b "${filename}" | grep -qE '^JSON'
AND
[[ ${filename} =~ \.json$ ]]