Yamlixir v1.0.3 Yamlixir View Source
Simple YAML parser for Elixir.
Link to this section Summary
Functions
Decodes a string of valid YAML into Elixir data
The same as decode/2 but raises a Yamlixir.DecodingError exception if it fails.
Returns the decoded YAML otherwise
Handles the sigil ~y for decoding YAML
Link to this section Types
Link to this type
decoded()
View Source
decoded()
View Source
decoded() :: [any()]
decoded() :: [any()]
Link to this type
error()
View Source
error()
View Source
error() :: Yamlixir.DecodingError.t()
error() :: Yamlixir.DecodingError.t()
Link to this type
options()
View Source
options()
View Source
options() :: keyword()
options() :: keyword()
Link to this type
yaml() View Source
Link to this section Functions
Link to this function
decode(yaml, options \\ []) View Source
Decodes a string of valid YAML into Elixir data.
Returns {:ok, decoded} on success and {:error, %Yamlixir.DecodingError{}} on failure.
Options
:at- Returns only the document at the given position in the list of documents. Expects input to be an integer.:keys- Controls how keys in maps are decoded. Defaults to strings. Possible values are::atoms- keys are converted to atoms usingString.to_atom/1:atoms!- keys are converted to atoms usingString.to_existing_atom/1
Examples
iex> Yamlixir.decode("")
{:ok, []}
iex> Yamlixir.decode("---")
{:ok, [%{}]}
iex> Yamlixir.decode(":")
{:error, %Yamlixir.DecodingError{}}
iex> Yamlixir.decode("a: b\nc: d")
{:ok, [%{"a" => "b", "c" => "d"}]}
iex> Yamlixir.decode("---\na: b\nc: d\n---\ne: f\ng: h")
{:ok, [%{"a" => "b", "c" => "d"}, %{"e" => "f", "g" => "h"}]}
iex> Yamlixir.decode("---\na: b\nc: d\n---\ne: f\ng: h", at: 0)
{:ok, %{"a" => "b", "c" => "d"}}
iex> Yamlixir.decode("---\na: b\nc: d\n---\ne: f\ng: h", at: -1)
{:ok, %{"e" => "f", "g" => "h"}}
iex> Yamlixir.decode("---\na: b\nc: d\n---\ne: f\ng: h", at: -1, keys: :atoms)
{:ok, %{e: "f", g: "h"}}
Link to this function
decode!(yaml, options \\ []) View Source
The same as decode/2 but raises a Yamlixir.DecodingError exception if it fails.
Returns the decoded YAML otherwise.
Examples
iex> Yamlixir.decode!("")
[]
iex> Yamlixir.decode!("---")
[%{}]
iex> Yamlixir.decode!(":")
** (Yamlixir.DecodingError) decoding error
iex> Yamlixir.decode!("a: b\nc: d")
[%{"a" => "b", "c" => "d"}]
iex> Yamlixir.decode!("---\na: b\nc: d\n---\ne: f\ng: h")
[%{"a" => "b", "c" => "d"}, %{"e" => "f", "g" => "h"}]
iex> Yamlixir.decode!("---\na: b\nc: d\n---\ne: f\ng: h", at: 0)
%{"a" => "b", "c" => "d"}
iex> Yamlixir.decode!("---\na: b\nc: d\n---\ne: f\ng: h", at: -1)
%{"e" => "f", "g" => "h"}
iex> Yamlixir.decode!("---\na: b\nc: d\n---\ne: f\ng: h", at: -1, keys: :atoms)
%{e: "f", g: "h"}
Link to this function
sigil_y(yaml, list) View Source
Handles the sigil ~y for decoding YAML.
It passes the string to decode!/2, returning the decoded data. Raises a
Yamlixir.DecodingError exception when given invalid YAML.
Modifiers
a: keys are converted to atoms usingString.to_existing_atom/1
Examples
iex> ~y"""
...> a: b
...> c: d
...> """
[%{"a" => "b", "c" => "d"}]
iex> ~y"""
...> a: b
...> c: d
...> """a
[%{a: "b", c: "d"}]