# JSON Schema

> Use the JSON Schema printed by `vidmake schema` (and served at /schema.json) for editor completion and pre-checks in other tools, and know what it checks compared with `vidmake validate`.

`vidmake schema` prints a [JSON Schema](https://json-schema.org) (draft 2020-12) describing project files: every
composition and layer field, the layer types, the animation forms, paints, presets and lint codes, with short
descriptions. It's generated from the same field lists the parser uses (a test fails if they drift apart), so it
always matches the binary that printed it.

```bash
vidmake schema > vidmake.schema.json
```

The schema of the current release is also served by this site at [/schema.json](https://vidmake.app/schema.json):

```
https://vidmake.app/schema.json
```

Use it for editor autocompletion and hover docs, and for a quick structural check in tools that don't have
vidmake installed. It is not a replacement for [`vidmake validate`](https://vidmake.app/docs/lint.md), which compiles the project.

## What's in it

```json title="vidmake schema (top)"
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vidmake.app/schema.json",
  "title": "vidmake project",
  "description": "Generated by `vidmake schema`. Run `vidmake docs` for semantics.",
  "oneOf": [
    { "type": "object", "additionalProperties": false, "required": ["compositions"],
      "properties": { "$schema": { "type": "string" }, "fonts": { ... }, "compositions": { ... } } },
    { "$ref": "#/$defs/bareComposition" }
  ],
  "$defs": { "time", "key", "ease", "anim", "num", "color", "paint", "preset", "lintCode", "layer", "composition", "bareComposition" }
}
```

(Abbreviated; the full schema is about 1,200 lines.)

| definition | describes |
|---|---|
| root | a project `{ "fonts", "compositions" }`, or a single bare composition with `layers` |
| `composition` | `id`, `width`, `height` required; `fps`, `duration` (time or `"auto"`), `background`, `props`, `layers`, `motionBlur`, `grain`, `description` |
| `bareComposition` | the same fields with `width`, `height` and `layers` required (`id` defaults to `main`) |
| `layer` | all 88 layer fields, `type` required and one of the 16 [layer types](https://vidmake.app/docs/layers.md) |
| `num` | a number, `"50%"`, an `"=expression"`, keyframes `[[t, v], ...]`, or a tween/keys object (see [animation](https://vidmake.app/docs/animation.md)) |
| `color`, `paint` | color strings and arrays, animated colors, `null`, linear/radial gradients (see [colors](https://vidmake.app/docs/colors.md)) |
| `time` | frames (number) or `"1.5s"`, `"500ms"`, `"45f"`, `"m:ss"` (see [time](https://vidmake.app/docs/time.md)) |
| `preset` | an `enter`/`exit` name or `{type, duration, delay, ease, distance}` |
| `lintCode` | `offCanvas`, `textOverflow`, `invisible`, `zeroDuration`, `afterEnd`, `all` (see [lint](https://vidmake.app/docs/lint.md)) |

Every object is closed (`additionalProperties: false`), so misspelled field names are flagged by the editor as
you type, the same mistakes `validate` reports as ``unknown field `fontsize` — did you mean `fontSize`?``.

## Editor setup

### VS Code

Point VS Code's JSON language service at the schema in your workspace or user `settings.json`:

```json title=".vscode/settings.json"
{
  "json.schemas": [
    {
      "fileMatch": ["project.json", "*.vidmake.json", "videos/**/*.json"],
      "url": "https://vidmake.app/schema.json"
    }
  ]
}
```

To pin the schema to the vidmake version you have installed (recommended: the hosted file tracks the latest
release), generate it into the repository and use a relative path:

```bash
vidmake schema > .vscode/vidmake.schema.json
```

```json title=".vscode/settings.json"
{
  "json.schemas": [
    { "fileMatch": ["project.json", "*.vidmake.json"], "url": "./.vscode/vidmake.schema.json" }
  ]
}
```

Regenerate the file after `vidmake update`. Other editors with a JSON language server (JetBrains IDEs, Neovim with
`jsonls`, Zed, Helix) take the same URL or file in their JSON schema mapping settings.

### `$schema` in the file

The project form accepts a `"$schema"` key at the top level, which many editors (including VS Code) pick up
without any settings:

```json title="project.json"
{
  "$schema": "https://vidmake.app/schema.json",
  "compositions": [
    { "id": "main", "width": 1920, "height": 1080, "duration": "5s", "layers": [] }
  ]
}
```

vidmake ignores the key when rendering. It is only allowed at the top of the project form: a file that is a single
bare composition rejects it (``composition `main`: unknown field `$schema` ``), so wrap the composition in
`{"compositions": [...]}` if you want it.

## Validating with other tools

Any draft 2020-12 validator works:

```bash
# Node (ajv-cli 5)
npx ajv-cli validate --spec=draft2020 -s vidmake.schema.json -d project.json

# Python (check-jsonschema)
check-jsonschema --schemafile vidmake.schema.json project.json
```

Because the root is a `oneOf` (project or bare composition), validators report the errors of both branches. The
first one is usually the useful one; the others say the file doesn't match the other branch. For a project with a
misspelled `fontSize`, ajv prints:

```output
project.json invalid
[
  {
    instancePath: '/compositions/0/layers/0',
    schemaPath: '#/additionalProperties',
    keyword: 'additionalProperties',
    params: { additionalProperty: 'fontsize' },
    message: 'must NOT have additional properties'
  },
  {
    instancePath: '',
    schemaPath: '#/required',
    keyword: 'required',
    params: { missingProperty: 'width' },
    message: "must have required property 'width'"
  },
  {
    instancePath: '',
    schemaPath: '#/oneOf',
    keyword: 'oneOf',
    params: { passingSchemas: null },
    message: 'must match exactly one schema in oneOf'
  }
]
```

Some validators only report "is not valid under any of the given schemas" at the root. Ask for the best-matching
error to get the useful one. In Python, with `jsonschema`:

```python title="check.py"
import json, sys
from jsonschema import Draft202012Validator
from jsonschema.exceptions import best_match

schema = json.load(open(sys.argv[1]))
project = json.load(open(sys.argv[2]))
error = best_match(Draft202012Validator(schema).iter_errors(project))
if error:
    print("/".join(map(str, error.absolute_path)) or "/", "-", error.message)
    sys.exit(1)
print("ok")
```

```output
$ python3 check.py vidmake.schema.json project.json
compositions/0/layers/0 - Additional properties are not allowed ('fontsize' was unexpected)
```

A schema check is useful where vidmake isn't installed: a web form that collects project JSON, a pre-commit hook,
an LLM tool definition that should only produce well-formed projects, or a server that accepts jobs before handing
them to a render worker.

> [!AGENT]
> If you generate projects through a structured-output or tool-calling API, the schema can constrain the shape.
> Still run `vidmake validate` on the result: the schema can't know whether a font exists, a file is there, or an
> expression parses.

## Schema vs `vidmake validate`

The schema checks **shape**. `validate` compiles the project the way `render` does, then lints it.

| check | schema | `validate` |
|---|---|---|
| unknown or misspelled fields | yes | yes, with a "did you mean" suggestion |
| required composition fields, value types, enums (`blendMode`, `lineCap`, `fit`, ...) | yes | yes |
| `lint` codes | yes | yes |
| a field that doesn't apply to the layer type (`fontSize` on a `rect`) | no: every layer field is allowed on every type | yes: ``field(s) fontSize do not apply to `rect` layers`` |
| fields required by a type (`text` for text, `src` for media, `d` for path, `ref` for use) | no | yes |
| files exist (`src`, font `path`, captions), media has the expected streams | no | yes |
| font families are installed or declared | no | yes |
| expression syntax and function names (`"=sinn(t)"`) | no | yes |
| easing, preset and transition names | no (any string) | yes |
| time strings | basic pattern only | fully parsed |
| `{{prop}}` placeholders | no; and placeholders in enum or time fields fail the schema (see below) | substituted first, then checked |
| `attach` targets, `use` references, series children having durations | no | yes |
| layout lint: off-canvas, overflowing, invisible, mistimed layers | no | yes, as [warnings](https://vidmake.app/docs/lint.md) |

> [!WARNING]
> The schema validates the file **before** [props](https://vidmake.app/docs/props.md) are applied. A placeholder in a field with an enum
> or a pattern, such as `"blendMode": "{{mode}}"` or `"duration": "{{seconds}}"`, is valid for vidmake but fails the
> schema check. Numeric and color fields accept any string, so `"x": "{{left}}"` passes both.

The order that catches the most mistakes for the least work: editor schema while typing, `vidmake validate` before
looking at anything, then [storyboard and inspect](https://vidmake.app/docs/inspecting.md).
