CDDL Reference
cddl-aiken supports a JSON-oriented subset of CDDL (RFC 8610). Every schema must define two top-level rules: key and value.
Primitive types
| CDDL type | CBOR major type | Description |
|---|---|---|
uint |
0 | Unsigned integer |
int |
0 or 1 | Signed integer |
bstr |
2 | Byte string |
tstr |
3 | Text string (UTF-8) |
bool |
7 | Boolean |
null |
7 | Null |
Maps
Maps use text keys (JSON-style):
Map keys are validated in canonical CBOR order (RFC 7049 §3.9) — shorter keys first, then lexicographic. The compiler sorts keys automatically; the CDDL source order doesn't matter.
Arrays
Fixed-size positional arrays:
The generated validator checks that the array has exactly the declared number of elements and validates each in order.
Choices
Union types via /:
The validator tries each alternative in order and accepts the first match.
Occurrence indicators
Control field cardinality in maps:
| Indicator | Meaning | Map count effect |
|---|---|---|
| (none) | Required (exactly 1) | must be present |
? |
Optional (0 or 1) | may be absent |
* |
Zero or more | may be absent |
+ |
One or more | must be present |
Constraints
Integer constraints
| Constraint | Generated check |
|---|---|
.le N |
expect v <= N |
.ge N |
expect v >= N |
.eq N |
expect v == N |
Size constraints
For byte strings and text strings:
| Constraint | Generated check |
|---|---|
.size N |
expect length == N |
.size (N..M) |
expect length >= N and expect length <= M |
Named rules
Rules can reference other rules:
Comments
Lines starting with ; are comments:
Unsupported features
The following CDDL features are not supported:
- CBOR tags (
#6.N(type)) - Floating point types
- Generics, sockets, plugs
.cbor/.cborseq/.regexpcontrols- Indefinite-length encodings
- Integer keys in maps