Back to articles
Pkl Has a Free Configuration Language by Apple — Type-Safe Config That Generates JSON, YAML, and Plist
NewsDevOps

Pkl Has a Free Configuration Language by Apple — Type-Safe Config That Generates JSON, YAML, and Plist

via Dev.to DevOpsAlex Spinov

The Config Problem YAML: indentation errors that break prod. JSON: no comments, no variables. TOML: limited nesting. Jsonnet: nobody knows it. Pkl (Pickle) by Apple is a typed configuration language. Write config once, generate JSON, YAML, XML, or Plist. With validation. What Pkl Gives You Typed Configuration class ServerConfig { host: String port: Int(isBetween(1, 65535)) debug: Boolean = false workers: Int(isPositive) = 4 } production: ServerConfig = new { host = "api.example.com" port = 443 workers = 16 } staging: ServerConfig = (production) { host = "staging.example.com" debug = true workers = 2 } Staging inherits from production. Override only what's different. Validation Built In class DatabaseConfig { host: String(!isEmpty) port: Int(isBetween(1, 65535)) maxConnections: Int(isBetween(1, 1000)) sslMode: "disable"|"require"|"verify-full" } Invalid config? Compile-time error. Not a runtime crash. Generate Any Format pkl eval config.pkl -f json # → config.json pkl eval config.pkl -f

Continue reading on Dev.to DevOps

Opens in a new tab

Read Full Article
9 views

Related Articles