emilianobovetti/elm-yajson/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Yajson.Object

Module for object specific helpers.

Access

keys : Json -> List String

Takes a json object and returns its keys as list of strings. Returns an empty list if the value isn't an object.

keys (ofInt [ "I" => 1, "II" => 2, "III" => 3 ])
    == [ "I", "II", "III" ]
values : Json -> List Json

Takes a json object and returns its values as list of strings. Returns an empty list if the value isn't an object.

values (ofInt [ "I" => 1, "II" => 2, "III" => 3 ])
    == [ Number 1, Number 2, Number 3 ]

Map

map : (String -> Json -> a) -> Json -> List a

Maps a json object.

mapKeys : (String -> a) -> Json -> List ( a, Json )

Like map, but maps only the keys.

mapValues : (Json -> a) -> Json -> List ( String, a )

Like map, but maps only the values.

filterMap : (String -> Json -> Maybe a) -> Json -> List a

Given a funcion fn : String -> Json -> Maybe a maps a json object, removes Nothings and returns a list.

If the json value is not an object returns an empty list.

filterMapKeys : (String -> Maybe a) -> Json -> List ( a, Json )

Like filterMap, but fn maps only the keys.

filterMapValues : (Json -> Maybe a) -> Json -> List ( String, a )

Like filterMap, but fn maps only the values.

Creation

ofString : List ( String, String ) -> Json

Wraps a list of string pairs in a json object.

ofString [ "name" => "value" ]
    == Object [ "name" => String "value" ]
ofFloat : List ( String, Float ) -> Json

Wraps a list of pairs of string and float in a json object.

ofFloat [ "pi" => 3.14, "e" => 2.718 ]
    == Object [ "pi" => Number 3.14, "e" => Number 2.718 ]
ofInt : List ( String, Int ) -> Json

Wraps a list of pairs of string and int in a json object.

ofInt [ "I" => 1, "II" => 2 ]
    == Object [ "I" => Number 1, "II" => Number 2 ]
ofBool : List ( String, Bool ) -> Json

Wraps a list of pairs of string and bool in a json object.

ofBool [ "hot" => True, "cold" => False ]
    == Object [ "hot" => Bool True, "cold" => Bool False ]