yaml
YAML serialization and deserialization.
Functions
encode value
Serializes a Do value to a YAML string.
Parameters
| Name | Type | Description |
|---|---|---|
value |
the value to serialize |
Returns
Str -- YAML string
Errors
| Exception | Condition |
|---|---|
TypeError |
A value is not YAML-representable, such as binary data or a custom object |
Type mapping:
| Do Type | YAML Value |
|---|---|
nil |
null |
Bool |
boolean |
Int |
integer |
Float |
float |
Str |
string |
Sym |
string |
array |
sequence |
dict |
mapping |
assert_eq (encode nil) "~"
assert_eq (encode [1, 2, 3]) "- 1\n- 2\n- 3"
assert_eq (decode $ encode [1, 2, 3]) [1, 2, 3]
decode yaml
Parses a YAML string into a Do value.
Parameters
| Name | Type | Description |
|---|---|---|
yaml |
Str |
YAML document to parse |
Returns
The parsed Do value.
Errors
| Exception | Condition |
|---|---|
ValueError |
The input is not valid YAML |
ValueError |
The input contains more than one document |
ValueError |
The input uses currently unsupported YAML features, including tags and aliases |
Type mapping:
| YAML Value | Do Type |
|---|---|
null |
nil |
| boolean | Bool |
| integer | Int |
| float | Float |
| string | Str |
| sequence | array |
| mapping | dict |