Skip to content
/ yamel Public

Yamel is a YAML parser and serializer lib for Elixir.

Notifications You must be signed in to change notification settings

GPrimola/yamel

Repository files navigation

Yamel - Yaml Serializer and Parser

CI Coverage Status Docs Hex.pm


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

Sponsor this project

  •  

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages