module Card exposing (..) import Json.Decode import Json.Decode.Pipeline as JDP type alias Prices = { usd : Maybe String , usd_foil : Maybe String , eur : Maybe String , eur_foil : Maybe String , tix : Maybe String } type alias Card = { scryfallId : String , name : String , setCode : String , rarity : String , oracleText : String , prices : Prices } decode : Json.Decode.Decoder Card decode = Json.Decode.succeed Card |> JDP.required "scryfall_id" Json.Decode.string |> JDP.required "name" Json.Decode.string |> JDP.required "set_code" Json.Decode.string |> JDP.required "rarity" Json.Decode.string |> JDP.required "oracle_text" (Json.Decode.nullable Json.Decode.string |> Json.Decode.map (Maybe.withDefault "") ) |> JDP.required "prices" decodePrices decodePrices : Json.Decode.Decoder Prices decodePrices = Json.Decode.succeed Prices |> JDP.required "usd" (Json.Decode.nullable Json.Decode.string) |> JDP.required "usd_foil" (Json.Decode.nullable Json.Decode.string) |> JDP.required "eur" (Json.Decode.nullable Json.Decode.string) |> JDP.required "eur_foil" (Json.Decode.nullable Json.Decode.string) |> JDP.required "tix" (Json.Decode.nullable Json.Decode.string)