Decode.oneOf

Try a bunch of different decoders. page

oneOf : List (Decoder a) -> Decoder a

This can be useful if the JSON may come in a couple different formats. For example, say you want to read an array of numbers, but some of them are null.

import String badInt : Decoder Int badInt = oneOf [ int, null 0 ] -- decodeString (list badInt) "[1,2,null,4]" == Ok [1,2,0,4]

~

To track successes and failures when using Decode.oneOf, you can use Result type to capture the outcome of each decoding attempt. Instead of directly applying Decode.oneOf to a list of decoders, you can map each decoder with Decode.attempt to wrap it in a Result type. This way, you can keep track of the success or failure of each decoding attempt.