kaml is the YAML library of Davils: a strict, lossless YAML 1.2 and 1.1 parser, emitter and document toolkit for
Kotlin on the JVM and on WebAssembly (wasmJs), built on Kore and safe to feed
with untrusted input. It is published under the Apache License 2.0.
| Module | Artifact | What it holds |
|---|---|---|
kaml-core |
com.davils:kaml-core |
Strict decoding of UTF-8, UTF-16 and UTF-32, a lossless parser, the event stream, the node graph, the failsafe, JSON, core and YAML 1.1 schemas, the emitter, the Yaml facade, the lossless syntax tree with incremental reparsing, the editor that keeps comments and the formatter |
kaml-document |
com.davils:kaml-document |
JSON Pointer, JSONPath on a linear-time I-Regexp engine, JSON Patch and JSON Merge Patch on the graph and in place on the text, layered merges with origins, diffs and redaction that fails closed |
kaml-serialization |
com.davils:kaml-serialization |
YamlFormat for kotlinx.serialization with positioned diagnostics, a closed registry for polymorphism and the conversion to and from JsonElement |
kaml-schema |
com.davils:kaml-schema |
JSON Schema: schemas derived from kotlinx.serialization descriptors, a typed schema model with a builder, a validator of drafts 2020-12, 2019-09 and 7 with exact numbers and linear-time patterns, diagnostics on the syntax tree, a registry without network access, associations and hints |
kaml is a Kotlin Multiplatform library for two targets, jvm and wasmJs, written for Kotlin 2.4 or newer. On the
JVM it requires JDK 25, and every module is a named Java module: com.davils.kaml.core, com.davils.kaml.document,
com.davils.kaml.serialization and com.davils.kaml.schema. On Wasm it is tested under Node.js and runs in the browser as well. Everything
that reads or writes YAML is common code, so both targets give the same results.
kaml is published to the Davils repository, not to Maven Central. Declare it for the com.davils group only, so no
other repository can ever serve a Davils artifact:
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
exclusiveContent {
forRepository { maven("https://repo.davils.com/releases") }
filter { includeGroupAndSubgroups("com.davils") }
}
mavenCentral()
}
}// build.gradle.kts
dependencies {
implementation("com.davils:kaml-core:1.1.2")
implementation("com.davils:kaml-document:1.1.2")
implementation("com.davils:kaml-serialization:1.1.2")
implementation("com.davils:kaml-schema:1.1.2")
}Gradle picks the JVM or the Wasm variant from these coordinates. A Maven build names the JVM artifacts directly,
such as com.davils:kaml-core-jvm.
when (val result = Yaml.Default.parse(text)) {
is YamlParseResult.Parsed -> {
val root = result.stream.single?.root
val port = root["server"]["port"].int()
}
is YamlParseResult.Failed -> result.diagnostics.forEach { diagnostic -> println(diagnostic) }
}
val text = Yaml.Default.emit(yamlMapping { "name" to "kaml"; "port" to 8080 })Parsing never throws for malformed input: the result carries diagnostics with a code, a range and an escaped
message. Every input is bounded by YamlLimits, which Yaml.Default sets for untrusted sources: the length of the
source, the depth, the nodes, the expansion of aliases and merge keys, anchors, scalars, collections, documents,
numbers, diagnostics and the output. A billion laughs document stops at its budget, not at the heap. For large
documents from a trusted source, yaml { limits = YamlLimits.Relaxed } raises every limit, but no limit is ever
unbounded.
val tree = YamlSyntaxTree.parse(text)
val result = YamlEditor(tree).set(YamlPath.ROOT.key("server").key("port"), yamlScalar(9090))
val edited = (result as? YamlEditResult.Edited)?.treeThe syntax tree keeps every character of the source and reparses only the documents an edit touches, always to the same tree as a full parse. The editor writes values through the emitter and validates comments, so nothing it writes can change the structure of the document around it.
val names = JsonPath.parse("$.users[?@.active == true].name").query(root)
val redaction = yamlRedaction {
path("$..password")
key { name -> name.endsWith("token") }
}
val redacted = redaction.redact(tree)JSONPath runs regular expressions on its own I-Regexp engine in linear time, and every query, patch, merge and diff is bounded by steps and results. JSON Patch and JSON Merge Patch apply to the node graph and in place to the text, keeping its comments. Redaction refuses what it cannot decide: a document with a parse error, or a target it cannot follow through an alias, a merge key or a duplicate key.
@Serializable
class Server(val host: String, val port: Int)
val server = YamlFormat.Default.decodeFromString<Server>(text)
val yaml = YamlFormat.Default.encodeToString(server)
when (val decoding = YamlFormat.Default.decodeOrFailure<Server>(text)) {
is YamlDecoding.Decoded -> decoding.value
is YamlDecoding.Failed -> decoding.diagnostics
}A type name in a document selects only a serializer the application registered or a sealed subclass; kaml never instantiates a class by its name. Messages never echo the input or the message of a serializer.
@Serializable
class Server(@YamlComment("The port to listen on") val port: Int = 8080, val host: String)
val schema: JsonSchemaObject = jsonSchemaOf<Server>()
val compiled = (JsonSchemaRegistry.Default.read(schema) as JsonSchemaReading.Read).schema
val result = compiled.validate(root)
val diagnostics = compiled.validate(YamlSyntaxTree.parse(text))jsonSchemaOf derives a schema in draft 2020-12 from a serializer, following the naming, polymorphism and unknown
keys of the YamlFormat; a JsonSchemaExtension adds keywords from the annotations of a property. The schema is a
typed model, JsonSchemaObject, that JsonSchemaNode.parse also reads from text, so two versions can be compared
keyword by keyword. A JsonSchemaRegistry compiles schemas of drafts 2020-12, 2019-09 and 7; references resolve only
to the schema, its resources and what a caller's loader returns, never to the network. Validation compares numbers
exactly, runs patterns as the regular subset of ECMA-262 in linear time, reports a pattern outside it as unsupported,
and stops at the limits of JsonSchemaLimits with an undecided result that is never valid. The official
JSON-Schema-Test-Suite passes on the JVM and on Wasm.
kaml treats every input as hostile: the bytes of a document, JSONPath expressions, JSON Pointers and patches, the layers of a merge, the targets of a redaction, and the values, comments, tags and anchors a caller asks it to write. SECURITY.md describes the threat model, the limits, the known limitations and how to report a vulnerability.
./gradlew checkcheck compiles with warnings as errors, runs Detekt, the tests on the JVM and on Wasm under Node.js, Kover at 97 %,
the API and semver check, the license header and changelog checks, Trivy and the Kreate assurance gate. It needs
JDK 25 and the network. See CONTRIBUTING.md and AGENTS.md.
Copyright 2026 Davils. Licensed under the Apache License, Version 2.0.