prozacchiwawa/elm-json-codec/3.0.0

NOTE: the latest version is 3.3.1

elm-json-codec

A library for creating combined encoders and decoders for Json in Elm, allowing composition.

module Test exposing (..)

import Json.Decode as JD
import JsonCodec as JC
import Platform exposing (worker)

type alias Test = { i : Int, b : Bool, f : Float, s : String }
    
codec =
    Test
        |> JC.first "i" JC.int .i
        |> JC.next "b" JC.bool .b
        |> JC.next "f" JC.float .f
        |> JC.next "s" JC.string .s
        |> JC.end

x =
    JD.decodeString (JC.decoder codec)
        "{\"i\":3,\"b\":false,\"f\":3.14,\"s\":\"hi there\"}"