kotlinx-schema-json
Type-safe JSON Schema models and DSL compliant with JSON Schema Draft 2020-12.
Provides Kotlin models for programmatic JSON Schema construction with full kotlinx-serialization support.
Platform Support: Multiplatform (Common, JVM, JS, Native, Wasm) • Kotlin 2.2+ • Requires kotlinx-serialization-json
Key Classes
JsonSchema - root schema model with type-safe property definitions
FunctionCallingSchema - OpenAI/Anthropic function calling format
DSL builders - fluent API for schema construction
Example
val schema = jsonSchema {
name = "User"
schema {
property("id") {
required = true
string { format = "uuid" }
}
property("role") {
oneOf {
discriminator(propertyName = "type") {
"admin" mappedTo "#/definitions/AdminRole"
}
}
}
}
}Content copied to clipboard
Features
Type-safe property definitions (string, number, integer, boolean, array, object)
Polymorphism support (
oneOf,anyOf,allOfwith discriminators)Type-safe enums using native Kotlin collections
Full kotlinx-serialization integration