Hi everyone, I’m quite new in Elm, I need to decode a json, using NoRedInk Json Decode pipe.
In my model I splitted the data that comes from server in several types and when I have to decode I have to do something like:
decoder : Decoder MyType
decoder =
Decode.succeed
(\field1 field2 subfield1 subfield2 field3 field4 ->
MyType
field1 field2
SubType
subfield1 subfield2
field3 field4
)
|> required “field1” string
|> required “field2” string
…
is there a better way that avoids the using of the anonymous function?
You could also break out a separate decoder for the sub-field to allow you to lean only on the default constructors you get. Json.Decode.Pipeline.custom allows you to specify a custom decoder to get data at the current scope in the JSON document rather than nesting under a key the way required does.