yaml
YAML serialization and deserialization.
Types
| Type | Description |
|---|---|
DecodeError |
Raised when decode is given invalid YAML, or YAML that uses
a feature it doesn't support. |
EncodeError |
Raised when encode is given a value that can't be written as
YAML as it stands. |
DecodeValue |
A value decoded from YAML. A mapping key may be any YAML value. |
EncodeValue |
A value that encodes as YAML. |
DecodeValue
@let DecodeValue = $
| nil
| Bool
| Int
| Float
| Str
| Array[DecodeValue]
| Dict[DecodeValue, DecodeValue]
A value decoded from YAML. A mapping key may be any YAML value.
EncodeValue
@let EncodeValue = $
| nil
| Bool
| Int
| Float
| Str
| Sym
| BaseArray[EncodeValue]
| Tuple[...EncodeValue]
| Record[...{*EncodeValue, **EncodeValue}]
| std.BaseStruct[{*EncodeValue, **EncodeValue}]
| BaseDict[EncodeValue, EncodeValue]
A value that encodes as YAML.
Functions
decode yaml -> DecodeValue
Parses a YAML string into a Do value.
| YAML Value | Do Type |
|---|---|
null |
nil |
| boolean | Bool |
| integer | Int |
| float | Float |
| string | Str |
| sequence | Array |
| mapping | Dict |
Parameters
| Name | Type | Description |
|---|---|---|
yaml |
Str |
YAML document to parse. |
Errors
DecodeError if the input is invalid, holds no document
or more than one, uses a tag or an alias, or has an integer too large for an
Int.
Example
let Dict(doc) = decode |
name: Alice
enabled: true
ports:
- 80
- 443
assert_eq $doc["name"] "Alice"
assert_eq $doc["enabled"] true
assert_eq $doc["ports"] [80, 443]
encode value -> Str
Serializes a Do value to a YAML string.
| Do Type | YAML Value |
|---|---|
nil |
null |
Bool |
boolean |
Int |
integer |
Float |
float |
Str |
string |
Sym |
string |
Array |
sequence |
Tuple |
sequence |
Dict |
mapping |
Struct |
mapping |
Record |
mapping |
Parameters
| Name | Type | Description |
|---|---|---|
value |
EncodeValue |
The value to serialize. |
Errors
| Exception | Condition |
|---|---|
TypeError |
A value has no YAML form, such as a Bin or a custom object. |
EncodeError |
The value contains itself, or an Int is outside the signed 64-bit range. |