gleam-community / codec

A package for keeping your JSON encoders and decoders in sync.
Apache License 2.0
15 stars 1 forks source link

gleam-community/codec

A package for keeping your JSON encoders and decoders in sync.

Package Version Hex Docs

✨ This project is written in pure Gleam so you can use it anywhere Gleam runs: Erlang, Elixir, Node, Deno, and the browser!


Quickstart

import gleam_community/codec

pub type Colour {
  RGB(Int, Int, Int)
  Name(String)
}

pub fn colour_codec() {
  codec.custom2(fn(rgb, name, value) {
    case value {
      RGB(r, g, b) -> rgb(r, g, b)
      Name(n) -> name(n)
    }
  })
  |> codec.variant3("RGB", RGB, codec.int(), codec.int(), codec.int())
  |> codec.variant1("Name", Name, codec.string())
  |> codec.construct
}

Installation

gleam-community packages are published to hex.pm with the prefix gleam_community_. You can add them to your Gleam projects directly:

gleam add gleam_community_codec

The docs can be found over at hexdocs.pm.