Repository navigation
First stable release of YamlKit, a YAML 1.2.2 parser and emitter for Swift with Codable support and no runtime dependencies.
Highlights
- Standards-compliant. The parser passes all 402 cases of the official YAML test suite. The suite checks events, resolved values and emitter round trips.
Codableintegration.YAMLDecoderandYAMLEncoderwork likeJSONDecoderandJSONEncoder. They support date, data and key strategies (including snake case and kebab case), sorted keys, and special handling forDate,Data(!!binary),URLandDecimal.- Readable output. The emitter writes idiomatic block-style YAML. It quotes strings only where necessary and has configurable indentation and line width.
- Layered API. Each stage of the YAML processing model can be used on its own: text → tokens → events (
YAML.parseEvents) → nodes (YAMLNode) → values. The same layers run in reverse for emitting. - Safe by default. Nesting depth is limited (512). Alias expansion is capped, which protects against "billion laughs" attacks. Duplicate mapping keys are rejected.
Features
- Full YAML 1.2.2 syntax: anchors and aliases, multi-document streams, block and flow collections, all scalar styles,
%YAMLand%TAGdirectives, and complex keys - Core, JSON and failsafe schemas, plus a
YAMLSchemaprotocol for custom schemas - Optional support for merge keys (
<<) - Input in UTF-8, UTF-16 and UTF-32 with automatic detection (BOM and null patterns)
- Errors with line and column. Decoding errors are mapped to
DecodingErrorwith the full coding path. - Swift 6 language mode with strict concurrency. All public types are
Sendable. - Non-recursive scanner, parser and composer, so deeply nested and very large documents don't overflow the stack
Documentation
- DocC API reference, a getting started guide and an architecture overview, published at https://objecthub.github.io/swift-yamlkit/documentation/yamlkit/
Scripts/build-documentation.shbuilds the documentation, andScripts/publish-documentation.shprepares it for GitHub Pages
Requirements
- Swift 6.0 or later
- macOS 13, iOS 16, tvOS 16 or watchOS 9 and later
Installation
.package(url: "https://github.com/objecthub/swift-yamlkit.git", from: "1.0.0")