A SARIF file can be wrong in three different ways, and they need three different checks. It can be invalid JSON. It can be valid JSON that does not conform to the SARIF schema. Or it can be a perfectly conformant file that the tool you are feeding it to still refuses, because that consumer imposes requirements the standard does not.
1. Schema conformance
The normative JSON schema is published by OASIS alongside the specification:
https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json
A mirror is served from SchemaStore,
which is the URL most files carry in their $schema property. Both describe
SARIF 2.1.0; the version property of a sarifLog must be the string
"2.1.0".
Any JSON Schema validator will check a file against it:
# .NET — the SARIF SDK's multitool
dotnet tool install --global Sarif.Multitool
sarif validate results.sarif
# Python — check against the OASIS schema with any JSON Schema validator
pip install check-jsonschema
check-jsonschema --schemafile sarif-schema-2.1.0.json results.sarif
2. Rules the schema cannot express
Plenty of the specification's requirements are prose constraints that JSON Schema has no way to state. A schema-valid file can still violate the standard. Common examples:
ruleIndexmust point at a real entry in the correspondingrulesarray — the schema only checks that it is an integer.- When
kindis not"fail",levelmust be absent or"none"(§3.27.10). - URIs in
artifactLocationmust be relative to a declareduriBaseId, or absolute — a bare Windows path is neither. - A
regionthat givesendLinemust not place it beforestartLine.
Sarif.Multitool validate checks a large set of these prose rules in addition
to the schema, and reports each one as a SARIF file of its own.
3. Consumer ingestion rules
This is where most real failures happen. A consumer may reject, silently truncate or partially ingest a file that is entirely valid SARIF.
GitHub
code scanning is the most commonly hit: it caps the number of results and runs it will
accept per upload, limits file size, requires partialFingerprints for stable
alert tracking (it will compute them itself if absent), and only surfaces a defined subset
of SARIF properties in the UI. The rest of a valid file is accepted and then ignored.
Check that document's limits before assuming your file is at fault.
Order the checks. Parse as JSON first, then validate against the schema, then run the prose-rule checks, and only then blame the consumer. Skipping to the last step is how an afternoon disappears.
Tools
Sarif.Multitool
Schema validation plus prose-rule checks, plus conversion, merging and rewriting. Source in sarif-sdk.
sarif-tools
Summarise, diff and convert SARIF from the command line — useful for working out what a file actually contains.
The OASIS schema
Feed it to whatever validator your language already has.
The result object
Most validation errors are on a result. The full property reference is here.