Convert between type-safe Elm values and YAML.
This is forked from terezka/yaml.
$ elm install MaybeJustJames/yamland import the library in an elm file like this
import Yaml.Decode -- for decodersFind the documentation on Elm's package website.
Say you have some YAML which looks like this:
---
- name:
first: Marie
last: Curie
occupation: [ chemist, physicist ]
age: 66
children: [ Irène, Ève ]
- name:
first: Alva
last: Myrdal
occupation: [ sociologist, diplomat, politician ]
age: 84
children: []
- name:
first: Svetlana
last: Alexievich
occupation: [ journalist, historian ]
age: 72
children: []
... to decode this, you could write
import Yaml.Decode (..)
type alias Woman =
{ name : String
, occupation : List String
, age : Int
, children : Int -- number of children
}
decoder : Decoder Woman
decoder =
map4 Woman
(map2 (\first last -> first ++ " " ++ last)
(at ["name", "first"] string)
(at ["name", "last"] string))
(field "occupation" (list string))
(field "age" int)
(map List.length (field "children" (list string)))
fromString
(list decoder)
yamlString -- The string containing the YAML example aboveThe branch parser-logging contains a version of the
parser logger
by @Janiczek.
This, along with writing detailed tests using elm-test is how I've been developing this package.
Please feel encouraged and welcome to submit bugs, PRs, etc.
Yaml.Encode to encode Elm values into YAML.You are free to copy, modify, and distribute this package with attribution under the terms of the MIT license. See the LICENSE file for details.