Documentation for YAML.
Summary
Functions
Decodes YAML strings into Elixir data structures or AST.
Functions
Decodes YAML strings into Elixir data structures or AST.
Options
:detailed- controls whether to return AST with metadata or simplified data (default:false)false(default) - returns plain Elixir maps, lists, and primitivestrue- returns full AST with metadata (line numbers, column numbers, tags)
:return- selects which decoded YAML documents are returned. It may be one of:auto,:first_documentor:all_documents.:auto(default) - automatically determines the return format based on the input. Single-document input returns the decoded value directly single document (map or list), while multi-document input returns a list with all decoded documents.:first_document- returns only the first decoded YAML document.:all_documents- returns all decoded YAML documents as a list.
:enable_merge- controls YAML merge key behavior (default:true)true(default) - processes<<as merge keys (YAML 1.1 behavior)false- treats<<as regular keys (YAML 1.2+ behavior)
:atomize_keys- controls whether map keys are converted to atoms (default:false)false(default) - keeps all keys as binary strings:safe- converts keys to atoms only if the atom already exists in the atom tabletrue- converts all keys to atoms (only use for trusted input)
:yamerl_opts- list of additional options passed directly to:yamerl_constr(default:[]). Note::str_node_as_binaryand:detailed_constrare always set internally and should not be passed here.{:schema, :failsafe | :json | :core | :yaml11}- YAML schema for type resolution (default::core){:node_mods, [module()]}- extra modules for custom node types (default:[]){:keep_duplicate_keys, boolean()}- preserve duplicate map keys (default:false)
Examples
iex> YAML.decode("- a: 1")
{:ok, [[%{"a" => 1}]]}
iex> YAML.decode("a: 1", return: :first_document)
{:ok, %{"a" => 1}}
iex> YAML.decode("a: 1", yamerl_opts: [{:schema, :core}, {:map_node_format, :map}])
{:ok, [%{"a" => 1}]}