I am struggling to convert a JSON response from OpenWeatherMap using NoRedInk/elm-decode-pipeline. I have managed to decode nested objects within the JSON, but I cannot do the same for an array of objects
I've included the code I currently have. It compiles but in fails when run with FetchWeather Err BadPayload ...
JSON
{
"weather":[{"id":804}],
"main":{"temp":289.5},
}
CODE
type alias OpenWeatherResponse =
{ main: MainResult
, weather: WeatherResult
}
type alias MainResult =
{ temp: Float }
type alias ConditionResult =
{ code: Int }
decodeOpenWeatherResponse : Decoder OpenWeatherResponse
decodeOpenWeatherResponse =
decode OpenWeatherResponse
|> required "main" decodeMain
|> required "weather" decodeConditions
decodeMain : Decoder MainResult
decodeMain =
decode MainResult
|> required "temp" float
decodeConditions : Decoder ConditionResult
decodeConditions =
decode ConditionResult
|> required "id" int -- This is clearly wrong --
decodeWeathermeant to bedecodeConditions? - Shuhei Kagawa