Represents a JavaScript value.
Convert data into a prettified string. The second argument specifies the amount of indentation in the resulting string.
Decode a JSON Value.
Parse the given string into a JSON value and then decode it.
Converter for String.
"hello" <== string ==> "\"hello\""Converter for Int.
42 <== int ==> "42"Converter for Float.
3.14 <== float ==> "3.14"Convert between an Elm Bool and a JSON boolean.
True <== bool ==> "true"Convert between some Elm value and a JSON null value.
"Some Value" <== null "Some Value" ==> nullConvert between an Elm List and a JSON array.
[ 1, 2, 3 ] <== list int ==> "[1,2,3]"Convert between an Elm Array and a JSON array.
Array.fromList [ 1, 2, 3 ] <== array int ==> "[1,2,3]"Convert between an Elm Dict and a JSON object.
Dict.fromList [ ( "alice", 42 ), ( "bob", 99 ) ] <== dict int ==> "{ \"alice\": 42, \"bob\": 99 }"A helper data type for building an object converter.
The following functions have a little tricky types, but you do not need to think about it! Just write like this:
type alias User =
{ name : String
, age : Int
, height : Maybe Float
}
converter : Converter User
converter =
object User <|
field "name" .name string
>> field "age" .age int
>> option "height" .height floatBuild an object converter with a constructor. Use it along with field or option.
Represents a field of an object. Use it along with object.
Optional version of field.
A pair of a function and its inverse. Same definition for Monocle.Iso.
Transform a converter. You need Iso a b because the decoder requires a function a -> b and the encoder requires an inverse function b -> a to map.
string2CharListIso : Iso String (List Char)
string2CharListIso =
Iso String.toList String.fromList
charList : Converter (List Char)
charList =
map string2CharListIso stringCreate the reversed isomorphism.
Compose two isomorphisms.
Convert between an Elm value and a nullable JSON value.
Just 42 <== nullable int ==> "42"
Nothing <== nullable int ==> "null"Do not do anything, just build a bridge between a JSON Value and an Elm Value.
For building a converter of recursive structure.
Use it like lazy (\_ -> converter) instead of just converter in order for the converter not to expand infinitly deep.
type Tree a
= Tree a (Maybe (Tree a)) (Maybe (Tree a))
tree : Converter a -> Converter (Tree a)
tree item =
object Tree <|
field "item" (\(Tree a _ _) -> a) item
>> option "left" (\(Tree _ l _) -> l) (lazy <| \_ -> tree item)
>> option "right" (\(Tree _ _ r) -> r) (lazy <| \_ -> tree item)
A pair of JSON encoder and decoder.
You can make custom converters using this directly if you need.