A GitHub Action to validate JSON files in your repository, with optional JSON Schema validation support.
- ✅ Validates JSON syntax in your repository
- ✅ Optional JSON Schema validation
- ✅ Automatic schema detection from
$schemaproperty - ✅ Supports relative and absolute schema paths
- ✅ Configurable ignore patterns - customize which files/folders to skip
- ✅ Optional failure mode - choose whether invalid JSON fails the action (default: true)
- ✅ Configurable folder scanning (defaults to entire repository)
- ✅ Clear error reporting with file paths
- ✅ Defaults to ignoring
node_modules,dist,lib, and.gitfolders - ✅ Comprehensive test suite
name: Validate JSON Files
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: woeterman94/json-validator-typescript-action@v1- uses: woeterman94/json-validator-typescript-action@v1
with:
folder: 'config'- uses: woeterman94/json-validator-typescript-action@v1
with:
folder: 'data'
schema: 'schemas/data.schema.json'You can customize which files and folders to ignore:
- uses: woeterman94/json-validator-typescript-action@v1
with:
folder: '.'
ignore: |
**/node_modules/**
**/dist/**
**/build/**
**/.git/**
**/temp/**Or use comma-separated patterns:
- uses: woeterman94/json-validator-typescript-action@v1
with:
folder: '.'
ignore: '**/node_modules/**, **/dist/**, **/build/**, **/.git/**, **/temp/**'JSON files can specify their own schema using the $schema property. The action will automatically validate these files against their specified schema:
{
"$schema": "./user.schema.json",
"name": "John Doe",
"email": "john@example.com"
}This feature works with:
- ✅ Relative paths (e.g.,
./schema.json,../schemas/user.schema.json) - ✅ Schemas stored in the same repository
- ❌ HTTP/HTTPS URLs (only local schemas are supported)
Note: If a global schema input is provided, it takes precedence over individual $schema properties.
When invalid JSON files are found, the action always displays them in this format:
Found invalid or incomplete json files:
❌ ./path/to/file1.json
❌ ./path/to/file2.json
This output format is consistent regardless of the fail-on-invalid setting. The fail-on-invalid parameter only controls whether the action exits with a failure status code.
| Input | Description | Required | Default |
|---|---|---|---|
folder |
Folder location to scan for JSON files | No | . (repository root) |
schema |
Path to JSON schema file for validation | No | `` (syntax validation only) |
ignore |
Glob patterns to ignore (comma or newline separated) | No | **/node_modules/**, **/dist/**, **/lib/**, **/.git/** |
fail-on-invalid |
Whether to fail the action when invalid JSON files are found | No | true |
| Output | Description |
|---|---|
valid-files |
Number of valid JSON files found |
invalid-files |
Number of invalid JSON files found |
name: Validate Configuration Files
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
validate-json:
runs-on: ubuntu-latest
name: Validate JSON Files
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate all JSON files
id: json-validation
uses: woeterman94/json-validator-typescript-action@v1
with:
folder: '.'
- name: Output results
if: always()
run: |
echo "Valid files: ${{ steps.json-validation.outputs.valid-files }}"
echo "Invalid files: ${{ steps.json-validation.outputs.invalid-files }}"jobs:
validate:
runs-on: ubuntu-latest
strategy:
matrix:
folder: ['config', 'data', 'schemas']
steps:
- uses: actions/checkout@v4
- name: Validate ${{ matrix.folder }}
uses: woeterman94/json-validator-typescript-action@v1
with:
folder: ${{ matrix.folder }}You can set fail-on-invalid: false to report invalid JSON files without failing the action:
- uses: woeterman94/json-validator-typescript-action@v1
with:
folder: '.'
fail-on-invalid: falseWith this setting, invalid files are still reported in the standard output format, but the action will exit successfully instead of failing. This is useful for reporting purposes or when you want to track JSON validity without blocking workflows.
- The action scans the specified folder (or entire repository) for all
.jsonfiles - Each JSON file is validated for proper syntax
- If a global schema is provided via the
schemainput, all files are validated against it - If no global schema is provided, the action checks each JSON file for a
$schemaproperty - Files with a
$schemaproperty are validated against their specified schema (if it exists locally) - The action reports all validation errors with file paths
- The action fails if any invalid JSON files are found
This action includes a comprehensive test suite. To run tests:
npm install
npm test
# Run with coverage
npm run test:coveragenpm install
npm run build
npm run package# Set environment variables for inputs
export INPUT_FOLDER="test-data/valid"
export INPUT_SCHEMA=""
# Run the action
node dist/index.jsMIT