Utilities for taking a JsonValue
and generating code for it using
elm-codegen.
annotation : JsonToElm.JsonValue -> Elm.Annotation.Annotation
Returns a Elm.Type.Annotation
for use in elm-codegen.
For example, running the following code:
toAnnotation (StringVal "test")
Will result in:
Elm.Annotation.string
{ decoderExpressionType : Maybe Elm.Annotation.Annotation }
A configuration object when generating elm-codegen decoders.
The decoderExpressionType
is an optional configuration for customizing how the expression generated by
the decoder
function will be annotated. Providing an annotation will overwrite whatever annotation would
normally be generated.
decoder : DecoderConfig -> JsonToElm.JsonValue -> ( Elm.Expression, Dict String Elm.Declaration )
Returns a Json.Decode
expression for use in elm-codegen.
For example, running the following code:
toDecoder (StringVal "test")
Will result in:
( Gen.Json.Decode.string, Dict.empty )
Note: This function may also return a declaration for a custom map
function if the passed JsonValue
is
a record with more than 8 keys. When returned, this should be added to the generated code!
encoder : JsonToElm.JsonValue -> Elm.Expression -> Elm.Expression
Takes a JsonToElm.JsonValue
and turns it into a Json.Encode
expression.
For example, running the following code:
toEncoder (StringVal "test")
Will result in:
Gen.Json.Encode.call_.string
expression : JsonToElm.JsonValue -> Elm.Expression
Returns a Elm.Expression
for use in elm-codegen.
For example, running the following code:
toElmJsonValue (JsonString "test")
Will result in:
Elm.string "test"