yaml
YAML serialization and deserialization.
Functions
to_str value
Serializes a Do value to a YAML string.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
the value to serialize |
Returns: str -- YAML string
Errors:
- Raises an error for values that are not YAML-representable, such as binary data or custom objects
Type mapping:
| Do Type | YAML Value |
|---|---|
nil |
null |
bool |
boolean |
int |
integer |
float |
float |
str |
string |
sym |
string |
array |
sequence |
dict |
mapping |
assert_eq (to_str nil) "~"
assert_eq (to_str [1, 2, 3]) "- 1\n- 2\n- 3"
assert_eq (from_str $ to_str [1, 2, 3]) [1, 2, 3]
from_str 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:
- Raises an error if the input is not valid YAML
- Raises an error if the input contains more than one document
- Raises an error for YAML features that are currently unsupported, including tags and aliases
Type mapping:
| YAML Value | Do Type |
|---|---|
null |
nil |
| boolean | bool |
| integer | int |
| float | float |
| string | str |
| sequence | array |
| mapping | dict |