{ "level": 1, "displayValue": "some text", "dataValue": "a string with the value" }
{ "level": 1, "displayValue": "some text", "dataValue": { "name": "xxx", "scope": "xxxx" } }
type DataValue
= Val String
| Key KeyType
type alias KeyType =
{ name: String, source: String }
type alias MyObj =
{ level: Int, displayValue: String, dataValue: DataValue}
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
{-|
Describes the ContentModel view type.
-}
type ContentModel =
TitledAsContentModel Titled
| MdContentAsContentModel MdContent
| PanelAsContentModel Panel
{-|
A JSON encoder for the ContentModel type.
-}
contentModelEncoder : ContentModel -> Encode.Value
contentModelEncoder model =
case model of
TitledAsContentModel titled -> titledEncoder titled
MdContentAsContentModel mdContent -> mdContentEncoder mdContent
PanelAsContentModel panel -> panelEncoder panel
{-|
A JSON decoder for the ContentModel type.
-}
contentModelDecoder : Decoder ContentModel
contentModelDecoder =
let
toContentModel typeName =
case typeName of
"Titled" -> map TitledAsContentModel titledDecoder
"MdContent" -> map MdContentAsContentModel mdContentDecoder
"Panel" -> map PanelAsContentModel panelDecoder
_ -> Decode.fail ("unknown type: " ++ typeName)
in
field "@type" Decode.string
|> andThen toContentModel