Skip to content

json_schema_passes

Validate every JSON / YAML / TOML / XML / dotenv / properties / INI / HCL file in paths against a JSON Schema document. Targets coerce through serde into the same serde_json::Value tree the schema sees, so a JSON-format schema can validate a YAML config (Kubernetes manifests, GitHub Actions workflows, Helm values.schema.json) or a TOML manifest (Cargo.toml, pyproject.toml) without separate schemas per format. The schema is loaded + compiled lazily on first evaluation and cached on the rule. Note the stringly-typed formats (XML, dotenv, .properties, INI): every value is a string, so a schema field must be typed string (with a pattern) — a type: integer / boolean / number assertion always fails against them. JSON / YAML / TOML / HCL keep native types.

Each schema-validation error becomes one violation, with the failing instance path and the schema’s error description in the message. A target that fails to parse produces a single parse-error violation, not a flood of schema errors against junk. Format is detected from the target’s extension (.json / .yaml / .yml / .toml / .properties / .ini / .cfg / .hcl / .tf / .tfvars / .nomad / .xml and the .csproj / .props / .targets family), or by filename for the .env family; pass format: to override.

Check-only — fixing schema violations is a “the user knows what value belongs there” problem, not alint’s.


OptionTypeRequiredDefaultDescription
formatone of json | yaml | yml | toml | xml | dotenv | properties | ini | hclOverride the auto-detected target format. When omitted, format is inferred from each target file’s extension (.json / .yaml / .yml / .toml / .properties / .ini / .cfg / .hcl / .tf / .tfvars / .nomad / .xml and the .csproj / .props / .targets XML family), or by filename for the .env family.
schema_pathstringyesPath to a JSON Schema file relative to the lint root. The schema must itself be JSON even when validating YAML / TOML targets.

Plus the common paths, level, id, and when fields. This table is generated from the JSON Schema; option types and defaults are authoritative.

A package.json that violates its JSON Schema

Section titled “A package.json that violates its JSON Schema”

The rule fires on this repository:

package.json
schemas/
schemas/package.schema.json
package.json
{
"name": "demo",
"version": "v1.x"
}
schemas/package.schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "version"],
"properties": {
"name": {"type": "string"},
"version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"}
}
}

With this .alint.yml:

version: 1
rules:
- id: package-conforms
kind: json_schema_passes
paths: "package.json"
schema_path: "schemas/package.schema.json"
level: error

alint check reports:

Terminal window
--- package.json ---------------------------------------------------------------
x error package-conforms
schema violation at `/version`: "v1.x" does not match
"^[0-9]+\.[0-9]+\.[0-9]+$"
Summary (1 violation):
x 1 error
0 passing * 1 failing

A .csproj auto-detected as XML that violates its JSON Schema

Section titled “A .csproj auto-detected as XML that violates its JSON Schema”

The rule fires on this repository:

App.csproj
schemas/
schemas/project.schema.json
App.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>banana</TargetFramework>
</PropertyGroup>
</Project>
schemas/project.schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["Project"],
"properties": {
"Project": {
"type": "object",
"required": ["@Sdk", "PropertyGroup"],
"properties": {
"@Sdk": {"type": "string"},
"PropertyGroup": {
"type": "object",
"required": ["TargetFramework"],
"properties": {
"TargetFramework": {"type": "string", "pattern": "^net[0-9]+\\.[0-9]+$"}
}
}
}
}
}
}

With this .alint.yml:

version: 1
rules:
- id: csproj-conforms
kind: json_schema_passes
paths: "App.csproj"
schema_path: "schemas/project.schema.json"
level: error

alint check reports:

Terminal window
--- App.csproj -----------------------------------------------------------------
x error csproj-conforms
schema violation at `/Project/PropertyGroup/TargetFramework`:
"banana" does not match "^net[0-9]+\.[0-9]+$"
Summary (1 violation):
x 1 error
0 passing * 1 failing

A package.json that conforms to its JSON Schema

Section titled “A package.json that conforms to its JSON Schema”

This repository is compliant:

package.json
schemas/
schemas/package.schema.json
package.json
{
"name": "demo",
"version": "1.2.3"
}
schemas/package.schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "version"],
"properties": {
"name": {"type": "string"},
"version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"}
}
}

With this .alint.yml:

version: 1
rules:
- id: package-conforms
kind: json_schema_passes
paths: "package.json"
schema_path: "schemas/package.schema.json"
level: error

alint check reports:

Terminal window
v All 1 rule(s) passed.

An explicit format xml parses an .config file that conforms to the schema

Section titled “An explicit format xml parses an .config file that conforms to the schema”

This repository is compliant:

app.config
schemas/
schemas/project.schema.json
app.config
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
schemas/project.schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["Project"],
"properties": {
"Project": {
"type": "object",
"required": ["@Sdk", "PropertyGroup"],
"properties": {
"@Sdk": {"type": "string"},
"PropertyGroup": {
"type": "object",
"required": ["TargetFramework"],
"properties": {
"TargetFramework": {"type": "string", "pattern": "^net[0-9]+\\.[0-9]+$"}
}
}
}
}
}
}

With this .alint.yml:

version: 1
rules:
- id: config-conforms
kind: json_schema_passes
paths: "app.config"
schema_path: "schemas/project.schema.json"
format: xml
level: error

alint check reports:

Terminal window
v All 1 rule(s) passed.