YAML doesn't validate. JSON doesn't have comments. TOML doesn't do schemas. Apple built Pkl to fix all three.
What Is Pkl?
Pkl (pronounced "pickle") is a configuration language from Apple. It's like YAML but with types, validation, and IDE support.
// server.pkl
port: UInt16 = 8080
host: String = "localhost"
maxConnections: UInt = 100
database {
host: String = "db.example.com"
port: UInt16 = 5432
name: String = "myapp"
maxPoolSize: UInt(isBetween(1, 100)) = 20
}
If you set port = -1 → compile error. If you set maxPoolSize = 200 → compile error. Before your app even starts.
Type Safety
// Define a schema
class ServerConfig {
host: String
port: UInt16
ssl: Boolean = false
workers: UInt(isPositive) = 4
allowedOrigins: Listing<String>
timeouts {
read: Duration = 30.s
write: Duration = 30.s
idle: Duration = 120.s
}
}
// Use it — any mistake is caught at evaluation time
production: ServerConfig = new {
host = "api.example.com"
port = 443
ssl = true
workers = 8
allowedOrigins {
"https://example.com"
"https://app.example.com"
}
}
Generate Any Format
# Generate JSON
pkl eval server.pkl -f json
# Generate YAML
pkl eval server.pkl -f yaml
# Generate .properties
pkl eval server.pkl -f properties
# Generate Kubernetes manifests
pkl eval k8s-deployment.pkl -f yaml > deployment.yaml
Write Pkl once, output JSON/YAML/properties/plist — whatever your tools need.
Why Pkl Over YAML
- Type checking — catch "port: abc" before deployment, not in production
- IDE support — autocomplete, hover docs, error highlighting
- Modularity — import, extend, override configurations
-
Built-in validation — constraints like
isBetween,isPositive,matches -
No "YAML gotchas" — no
Norway: false, no3.10: 3.1
Building configuration systems? Check out my developer tools or email spinov001@gmail.com.
Top comments (0)