miniBill/elm-codec/1.1.0

NOTE: the latest version is 2.3.1

elm-codecs

Build Status

This package allows you to build pairs of JSON encoders (a -> Value) and decoders (Decoder a), collectively called a Codec a.

Design Goals

The design goal is to be as type safe as possible while keeping a nice API. Using this package will greatly reduce the risk of unmatched encoders and decoders.

The packages re-exposes the Value and Decoder types from elm/json, so you don't need to import them too.

Examples

Basic usage

import Codec exposing (Codec, Value)

codec : Codec (List Int)
codec =
    Codec.list Codec.int

encode : List Int -> Json.Encode.Value
encode list =
    Codec.encoder codec list

decodeString : String -> Result Codec.Error (List Int)
decodeString s =
    Codec.decodeString codec s

Learning Resources

Ask for help on the Elm Slack.

You can also have a look at the FAQ.md file.