SilverBullet uses JSON Schema for validation of structured data. Schemas ensure that Frontmatter attributes, tag fields, and configuration options conform to expected types and shapes.
When you define a tag with tag.define, you can provide a schema that describes the expected attributes. The schemas of the built-in tags are defined the same way, in ^Library/Std/Infrastructure/Root Tags. SilverBullet validates objects against this schema and surfaces errors in the editor:
tag.define {
name = "contact",
schema = {
type = "object",
properties = {
email = schema.string(),
phone = schema.nullable("string"),
priority = schema.number(),
}
}
}
Pages or objects tagged with #contact will be validated against this schema — if a field has the wrong type, you’ll see a lint warning in the editor.
The config.define function uses schemas to validate configuration values:
config.define("myLibrary.config", {
type = "object",
properties = {
enabled = schema.boolean(),
maxItems = schema.number(),
}
})
This ensures that config.set("myLibrary.config", ...) only accepts values matching the schema.
The ^Library/Std/APIs/Schema library provides convenience functions like schema.string(), schema.number(), schema.array(typ), etc. for building JSON Schema objects in Lua. See the API page for the full list.
schema.ref("person") describes a reference: a single quoted wikilink such as owner: "[[Person/Alice]]", pointing at a page or at an object with an anchor ("[[$alice]]").
When schema validation fails for page and attributes, SilverBullet shows the error as a lint warning in the editor.
See also: Tag#User tags, API/jsonschema, API/config