gserde

warning: alpha package with poor code hygiene, including assert/panic/todo statements. Use understanding that this package is not ready for primetime.

Package Version Hex Docs

gleam add gserde

usage

  1. Create custom type with a singular variant constructor:
  2. Run gleam run -m gserde
  3. Observe src/foo_json.gleam, which has the goodies you need for json (de)serialization.
// src/foo.gleam
import gleam/option.{type Option}
pub type FooJSON {
 Foo(
   a_bool: Bool,
   b_int: Int,
   c_float: Float,
   d_two_tuple: #(Int, String),
   e_option_int: Option(Int),
   f_string_list: List(String),
 )
}

// src/my_module.gleam
import foo
import foo_json

pub fn serialization_identity_test() {
 let foo_1 = foo.Foo(..)

 let foo_2 = foo_1
   |> foo_json.to_string // ๐Ÿ‘€
   |> foo_json.from_string // ๐Ÿ‘€

 foo_1 == foo_2
}

todo

Further documentation can be found at https://hexdocs.pm/gserde.

Development

gleam test  # Run the tests
โœจ Search Document