Hey, thanks for the feedback! Didn't know that fact about `oneOf`. Today I switched over to the decode pipeline library. Indeed, it is just better - at least for me ;-)
Cheers, Sekib Am Dienstag, 27. Dezember 2016 15:11:35 UTC+1 schrieb Brian Hicks: > > Hey, glad you got it! A little feedback: > > 1. Try `oneOf` instead of `maybe`. `maybe` will fail for any failing part > of the contained decoder (so if "notes" is not there or suddenly an int.) > If you plan to change that at all in the future, you'll end up wondering > why it didn't work. > 2. Check out https://github.com/NoRedInk/elm-decode-pipeline. Even though > your decoder is really small now, `optional` from that package could help > you. (and IMO decoders written in the pipeline style are just *better*.) > > On Monday, December 26, 2016 at 3:39:55 PM UTC-6, Sekib Omazic wrote: >> >> Got it like this: >> >> decodeNotes : Decoder (List DailyNotes) >> decodeNotes = >> list (field "day_entry" decodeDailyNotes) >> >> >> decodeDailyNotes : Decoder DailyNotes >> decodeDailyNotes = >> map2 DailyNotes >> (field "id" int) >> (maybe (field "notes" string)) >> >> Didn't use type alias Notes at all and also added "maybe" to the "notes" >> field. >> >> Hopefully it helps somebody. >> >> >> Am Montag, 26. Dezember 2016 21:31:45 UTC+1 schrieb Sekib Omazic: >>> >>> Hi all, >>> >>> I got stuck trying to decode a list of JSON objects I get from server: >>> >>> -- JSON response from server >>> >>> [ >>> {"day_entry": {"id":1234,"notes":"Map Json "} }, >>> {"day_entry": {"id":5678,"notes":"Learn Elm"} } >>> ] >>> >>> -- types >>> >>> type alias Notes = >>> { dailyNotes : List DailyNotes >>> } >>> >>> >>> type alias DailyNotes = >>> { id : Int >>> , notes : String >>> } >>> >>> >>> -- my decoders >>> >>> decodeNotes : Decoder Notes >>> decodeNotes = >>> map Notes (field "day_entry" (list decodeDailyNotes)) >>> >>> >>> decodeDailyNotes : Decoder DailyNotes >>> decodeDailyNotes = >>> map2 DailyNotes (field "id" int) (field "notes" string) >>> >>> >>> It fails with Err BadPayload. >>> >>> Any help is appreciated. >>> >>> Thanks! >>> >> -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
