March Docs

Yaml

Simplified YAML parser (pure March, no FFI).

Supports: block mappings, block sequences, flow mappings {}, flow sequences [], plain scalars (string/int/bool/null), single-quoted and double-quoted strings, comments (#), document separator (---), inline comments.

Does NOT support: anchors (&), aliases (*), explicit tags (!!), multi-document streams, merge keys (<<), block scalars (| and >).

Public API: Yaml.parse(src) : Result(YamlValue, YamlError) Yaml.parse_exn(src) : YamlValue (panics on error) Yaml.to_string(v) : String Yaml.get(v, key) : Option(YamlValue) Yaml.get_in(v, keys) : Option(YamlValue) Yaml.get_str(v, key) : Option(String) Yaml.get_int(v, key) : Option(Int) Yaml.get_bool(v, key) : Option(Bool) Yaml.get_seq(v) : Option(List(YamlValue))

Types

typeYamlValueYamlValue#
typeYamlErrorYamlError = YamlError(String, Int, Int)#

Functions

fngetget(v : YamlValue, key : String) : Option(YamlValue)#

Get a key from a YMap value.

fnget_boolget_bool(v : YamlValue, key : String) : Option(Bool)#

Get a boolean value from a YMap.

fnget_inget_in(v : YamlValue, keys : List(String)) : Option(YamlValue)#

Navigate nested YMap values by a list of keys.

fnget_intget_int(v : YamlValue, key : String) : Option(Int)#

Get an integer value from a YMap.

fnget_seqget_seq(v : YamlValue) : Option(List(YamlValue))#

Get the list from a YSeq value.

fnget_strget_str(v : YamlValue, key : String) : Option(String)#

Get a string value from a YMap.

fnparseparse(src : String) : Result(YamlValue, YamlError)#

Parse a YAML string. Returns Ok(YamlValue) or Err(YamlError). Supports: block mappings, block sequences, scalars, flow {}/[], comments.

    Yaml.parse("name: alice\\nage: 30")
fnparse_exnparse_exn(src : String) : YamlValue#

Parse YAML, panicking on error.

fnto_stringto_string(v : YamlValue) : String#

Serialize a YamlValue to a YAML string.