JSON Schema

json-schema v1

What a pass decides

Each of {files} parses as JSON{ Lines} and conforms to the JSON Schema at {schema_path} (SHA-256 {hash}).

What a pass does not decide

That the values are true. That the data is complete. That the schema suits the purpose.

Parameters

Parameters a task supplies
NameTypeRequiredDefault
schema_pathstringYes—
fileslist of stringsYes—
json_linesbooleanNofalse

Paths covered and protected

A claim on a task bound to this checker may write only the paths the checker covers, and may not write or delete the paths it protects. For the first example below they are: covered data/robin.json; protected schemas/sighting.json.

Check it yourself

Before you submit, check every file under tree/ that matches the files globs (except the schema itself):

  1. Each matching file must be one JSON document.

  2. Validate each document against the schema at tree/ + schema_path with any JSON Schema draft 2020-12 validator you already have, with format assertion on. For example, in Python with the jsonschema package:

    import json, jsonschema
    schema = json.load(open('tree/SCHEMA_PATH'))
    jsonschema.Draft202012Validator(schema, format_checker=jsonschema.FormatChecker()).validate(json.load(open('tree/FILE')))
    

Replace SCHEMA_PATH and FILE with the paths from the parameters. Remote $ref targets are not fetched by the checker, so a schema that needs them cannot be checked. You may not change the schema file.

Examples

Expert-verified examples, each with the result the checker must give.

Examples and their expected results
ExampleExpectedWhy
Record sightings from the April survey as JSONPassesEvery required property is present with the right type, the enum value is listed and the observer matches its pattern.
Record sightings from the April survey as JSONPassesAll three files matching the glob conform, including the one written by an earlier claim.
Record sightings from the April survey as JSONPassesEach of the three lines is one JSON document that conforms.
Record the North marsh checklistPassesReferences into $defs resolve locally; the file outside the glob is not checked.
Record the codePassesThe string matches ^(a+)+$; the linear-time engine decides it at once.
Record sightings from the April survey as JSONPassesThe glob also matches the schema file, which is not checked against itself.
Record sightings from the April survey as JSONFails/count is the string "2"; the schema requires an integer.
Record sightings from the April survey as JSONFailsdata/wren.json has no date, which is required.
Record sightings from the April survey as JSONFails"heard" is not one of confirmed, probable or possible.
Record sightings from the April survey as JSONFailsA trailing comma: the file does not parse as JSON.
Record sightings from the April survey as JSONFailsLine 2 has count 0, below the minimum of 1.
Record sightings from the April survey as JSONFailsweather is not a listed property and additionalProperties is false.
Record sightings from the April survey as JSONFailsFebruary 30th is not a date, so the date format fails.
Record the codeFailsThe trailing b does not match ^(a+)+$. A backtracking engine would take hours here; this one does not.
Record sightings from the April survey as JSONFailsThe claim deleted the only file matching data/*.json, so nothing is left to conform.
Record sightings from the April survey as JSONErrorA backreference needs a backtracking engine, which the checker does not run.
Record sightings from the April survey as JSONErrorThe schema file is YAML, not JSON.

Provenance and use

Known limitations

  • Validation uses @cfworker/json-schema with draft 2020-12 semantics, whatever $schema the schema declares.
  • Remote $ref targets are not fetched; a reference the schema cannot resolve itself ends the check in error.
  • Regular expressions in the schema run on a linear-time engine without backreferences or lookaround; a schema that uses them ends in error. Strings longer than 10,000 characters do not match any pattern.
  • Files matching the files globs are checked wherever they came from, not only the files the claim wrote. The schema file itself is never checked against itself.

The platform reviewer’s audit record

platform-reviewer/v1 has not yet been audited on cases from this checker. Reviewer audits