Maybe use *andThen* <http://package.elm-lang.org/packages/elm-lang/core/4.0.5/Json-Decode#andThen>? Looks like that would let you decode part of the event, identify its type, and then branch to different decoders for different event types.
On Wed, Aug 31, 2016 at 11:07 AM, Thomas Coopman <[email protected]> wrote: > I'm struggling with parsing json data that contains different kinds of > data. > > My json structure looks like this: > > [{event: A, data: {id: 1, name: 'foo'}}, event: B, data: {id: 1, address: > 'bar'}}] > > I want to parse this structure to > > type Event = EA A | EB B > > type alias A = {id : Int, name: String} > > type alias B = {id: Int, address: String} > > decodeEvents : Json.Decode.Decoder List Event > > So I want to write *decodeEvents*. > > My question is, how can I do this? I want to write some if/case structure > that checks the event name to parse the correct event. > I was thinking of using *oneOf* on the data, but the data can have the > same structure for different events. > > -- > 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. > -- 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.
