yamel

Yamel is a YAML parser and serializer lib for Elixir.

Downloads
4.4K
Stars
4
Committers
7

Yamel - Yaml Serializer and Parser


An yaml parser and serializer to work with Yaml files in Elixir.

Installation

Add yamel to your list of dependencies in mix.exs:

def deps do
  [
    {:yamel, "~> 2.0.4"}
  ]
end

Usage

yaml_string = ~S"""
foo: bar
zoo:
  - caa
  - boo
  - vee
"""

Yamel.decode!(yaml_string) # equivalent to Yamel.decode!(yaml_string, keys: :string)
=> %{"foo" => "bar", "zoo" => ["caa", "boo", "vee"]}

Yamel.decode!(yaml_string, keys: :atom)
=> %{foo: "bar", zoo: ["caa", "boo", "vee"]}

Yamel.encode!(["caa", :boo, :"\"foo\""])
=> "- caa\n- boo\n- \"foo\"\n\n"

%{foo: :bar, zoo: :caa}
|> Yamel.encode!()
|> Yamel.IO.write!("/to/file.yml")
=> :ok

%{foo: value} = Yamel.IO.read!("/from/file.yaml")

Deriving

defmodule MyApp.MyStruct do
  defstruct [:field1, :field2, :field3, field4: true]
  @derive {Yamel.Encoder, only: [:field2, :field4]}
end
Package Rankings
Top 36.43% on Hex.pm
Badges
Extracted from project README
Coverage Status Docs