Elm JSON decoder for Union type with data
问题 My json looks like this: {"name": "providerWithVal", "value": "example"} or like this: {"name": "provider2"} or {"name": "provider3"} My Elm union type is defined like so: type Provider = ProviderWithVal String | Provider2 | Provider3 I can write a decoder for a union type without data attached. But ProviderWithVal takes a string and I'm not sure how to make it all work. This is what I have so far: import Json.Decode as D providerDecoder : D.Decoder Provider providerDecoder = D.field "name" D