Check JSON config files for parse errors (line and column) and validate them against a JSON Schema 2020-12 with ajv-cli or Python jsonschema, with a fix for every error.
---
name: json-config-validator
description: Validates JSON configuration files — first that they parse (reporting line and column), then against a JSON Schema (draft 2020-12) with a real validator such as ajv-cli or Python jsonschema — and reports every violation with its JSON path and a suggested correction. Writes the schema from stated rules when none exists. Use when a config file fails to load, before deploying config changes, or when asked to check or write a schema for package.json-style, app, CI or tool config files.
compatibility: Uses Node.js (npx ajv-cli) or Python 3 with the jsonschema package; installing either validator needs registry access.
metadata:
version: "1.0.0"
category: "Development Tools"
---
# JSON Config Validator
## Inputs to collect
- The config file(s) and what reads them (application, tool, version).
- The rules: an existing schema file, the tool's published schema (many tools publish one; check SchemaStore or the tool's docs), or rules the user states (required keys, types, allowed values, ranges, patterns).
- Whether unknown keys are errors (`"additionalProperties": false`) or allowed.
## Workflow
1. **Parse check.** `python3 -c "import json,sys; json.load(open(sys.argv[1]))" config.json` or `node -e "JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))" config.json`. On failure report the message with line and column (Python prints e.g. `Expecting property name enclosed in double quotes: line 3 column 43`) — usually a trailing comma, comment or single quotes. JSON allows none of these; if the reader accepts JSONC or JSON5, say so and validate with that parser instead.
2. **Schema.** Use the existing or published schema. Otherwise write one with `"$schema": "https://json-schema.org/draft/2020-12/schema"`, `required`, `type`, `enum`, `minimum`/`maximum`, `pattern`, and `additionalProperties` as agreed. Show the schema to the user before relying on it.
3. **Validate**, collecting all errors rather than the first:
- Node: `npx -y ajv-cli@5 validate --spec=draft2020 --all-errors --errors=text -s config.schema.json -d config.json` (exit code 1 when invalid).
- Python: `Draft202012Validator(schema).iter_errors(data)` from the jsonschema package; call `Draft202012Validator.check_schema(schema)` first.
4. **Report** each error as path → problem → fix, for example `port — "8080" is a string, expected integer → use 8080`.
5. **Semantic checks the schema cannot express** (only if asked): referenced files exist, ports are not already used, URLs resolve. Label these separately.
6. **Fixes.** Propose the corrected JSON as a diff. Do not rewrite the user's file unless asked; preserve key order and formatting when you do.
## Output format
```
<file>: parse OK | parse error at line L, column C: <message>
Schema: <path or "drafted, see below"> (draft 2020-12)
Errors (n):
| JSON path | Problem | Suggested fix |
Warnings: <unknown keys if allowed, defaults applied, semantic notes>
```
## Limitations
- A schema checks shape and values, not whether the application actually behaves correctly with them.
- `default` in JSON Schema is an annotation; validators do not insert defaults unless configured to.
- Validators differ on optional `format` checks (email, uri); ajv needs ajv-formats for them.
## Example
Rules: port integer 1–65535 (required), logLevel one of debug/info/warn/error, database.url required and starting with postgres:// or postgresql://, no other top-level keys.
File: `{"port": "8080", "logLevel": "verbose", "database": {"url": "mysql://db/app"}, "debug": true}`
Good result: four errors — root `debug` not allowed, `/port` must be integer, `/logLevel` not in the allowed values, `/database/url` does not match the pattern — each with a fix, plus the drafted schema.
Generate a GitHub Actions (or other CI) pipeline from the repo's real scripts, with least-privilege permissions, caching, concurrency and a gated deploy.
Generate a compose.yaml for your app, database and cache with health-checked startup, named volumes and secrets in .env, validated with docker compose config.
Automate notifications and alerts
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
An app fails at startup after someone edited config.json, and the team wants the file checked against explicit rules before redeploying.
Validate this config: {"port": "8080", "logLevel": "verbose", "database": {"url": "mysql://db/app"}, "debug": true}. Rules: port integer 1-65535 required; logLevel one of debug/info/warn/error; database.url required and must start with postgres:// or postgresql://; no other top-level keys.Parse OK. A drafted draft-2020-12 schema (required port and database; additionalProperties false; enum for logLevel; pattern ^postgres(ql)?:// for database.url) is shown. The validator was actually run (for example `npx -y ajv-cli@5 validate --spec=draft2020 --all-errors ...` exiting 1). Four errors are listed with fixes: root 'debug' not allowed → remove or add to the schema; /port is a string → 8080; /logLevel 'verbose' not allowed → 'debug'; /database/url does not match the pattern → use a postgres:// URL or change the rule. The corrected JSON comes as a diff, and the file is not overwritten unless asked.
AI Agent Skills are reusable workflow packages that extend your AI coding assistant with multi-step capabilities. Install JSON Config Validator by following these steps.
SKILL.md inside, in the location documented by your client. Do not assume every AI application reads the same directory.Requires an Agent Skills-compatible client; supported locations and activation vary by version. Read the SKILL.md setup guide. MCP connects tools and data and does not, by itself, install a skill.
Generate a GitHub Actions (or other CI) pipeline from the repo's real scripts, with least-privilege permissions, caching, concurrency and a gated deploy.
Generate a compose.yaml for your app, database and cache with health-checked startup, named volumes and secrets in .env, validated with docker compose config.
Automate notifications and alerts