Some functions to deal with json data.
decoder : Json.Decode.Decoder (Boxed c)
Handy decoder for the Boxed
type. It does not decode tuples or
custom values. It will only decode dictionaries at top level if they are only
one level deep and its values are all primitives. Same with lists. Composite
objects deeper than that will be stored as Json.
expand : Boxed c -> Boxed c
Turn raw json into a fully developed object defined in terms of Dictionary, Lst and primitives.
str = "{ \"banker\": { \"name\": \"Alice\" }, \"fireman\": { \"age\": 42 } }"
boxed = decodeString decoder str |> Result.withDefault Null
expand boxed == Dictionary (Dict.fromList [("banker",Dictionary (Dict.fromList [("name",Str "Alice")])),("fireman",Dictionary (Dict.fromList [("age",Integer 42)]))])
encoder : Boxed c -> Json.Encode.Value
Handy encoder for the Boxed
type. It only encodes primitives, Dictionary
and Lst. If it encouters a Tup
or a Custom
, it will render them null
.