Untested, but probably works:

decoder = Json.Decode.dict Json.Decode.string |> Json.Decode.map
(Dict.toList >> List.map (\(name,value) -> Config name value))

​

2016-08-05 17:44 GMT+02:00 Petr Huřťák <petr.hur...@gmail.com>:

> Hi,
>
> I have JSON from API with following data structure
>
> {
>   "configurations": {
>     "configName1": "configValue1",
>     "configName2": "configValue2",
>     "configName2": "configValue3"
>   }
> }
>
>
>
> How do I construct Decoder which outputs data structure which is little
> easier to work with in elm, like following:
>
> type alias Configs = List Config
>
> type alias Config =
>     { name : String
>     , value : String
>     }
>
>
>
> which would result with following Elm data structure
>
> configs : Configs
> configs =
>     [ { name: "configName1", value: "configValue1" }
>     , { name: "configName2", value: "configValue2" }
>     , { name: "configName3", value: "configValue3" }
>     ]
>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to