Skip to content

brunoborges/toml-schema

Repository files navigation

TOML Schema

Reference implementations License TOML 1.0 Java 25 Go 1.23 Rust 1.75

TOML Schema is a TOML-based schema language for describing and validating the structure, names, and value types of TOML configuration files.

A TOML Schema document is itself a valid TOML document. Validators can use it to catch misconfiguration before production and tooling can use it for editor validation, completion, and hints.

Documentation

  • Specification - the TOML Schema language, validation semantics, file extension, MIME type, and TOML schema-reference metadata.
  • ABNF grammar - a compact grammar for the TOML Schema vocabulary and document shape, layered on top of TOML 1.0.
  • Self-schema - a TOML Schema document for TOML Schema documents.
  • Example schema and example TOML document - a worked example used by the reference implementation tests.
  • Reference implementations - implementation status, Java CLI/library usage, and conformance expectations.

Quick example

TOML document:

title = "TOML Example"

[database]
enabled = true
ports = [8000, 8001, 8002]

TOML Schema document:

[toml-schema]
version = "1.0.0"

[elements.title]
type = "string"

[elements.database]
type = "table"

    [elements.database.enabled]
    type = "boolean"

    [elements.database.ports]
    type = "array"
    arraytype = "integer"

Reference implementations

Java, Go, and Rust reference implementations live under reference-implementations/. See Reference implementations for implementation status, build/test commands, CLI usage, schema extraction, and conformance expectations.

Schema reference from TOML

A TOML document can point to a schema with reserved metadata:

[toml-schema]
version = "1.0.0"
location = "config.tosd"

See SPEC.md for the full behavior.

Related work

There is an ongoing effort to bring schema support for TOML under toml-lang/toml#792. This proposal intentionally focuses on a smaller TOML-native schema language.

Contributors

Thanks to my friends!

License

TOML Schema is licensed under the MIT License.