Current section
Files
Jump to
Current section
Files
src/internal/foo_json.gleam
// This file was generated using gserde
import gleam/json
import gleam/dynamic/decode
import internal/foo
pub fn to_json(t: foo.FooJson) {
json.object([#("a_bool", json.bool(t.a_bool)), #("b_int", json.int(t.b_int)), #("c_float", json.float(t.c_float)), #("d_two_tuple", json.preprocessed_array([json.int(t.d_two_tuple.0), json.string(t.d_two_tuple.1)])), #("e_option_int", json.nullable(t.e_option_int, json.int)), #("f_string_list", json.array(t.f_string_list, json.string))])
}
pub fn to_string(t: foo.FooJson) {
json.to_string(to_json(t))
}
pub fn get_decoder_foo() {
use a_bool <- decode.field("a_bool", decode.bool)
use b_int <- decode.field("b_int", decode.int)
use c_float <- decode.field("c_float", decode.float)
use d_two_tuple <- decode.field("d_two_tuple", {
use el0 <- decode.field(0, decode.int)
use el1 <- decode.field(1, decode.string)
decode.success(#(el0, el1))})
use e_option_int <- decode.field("e_option_int", decode.optional(decode.int))
use f_string_list <- decode.field("f_string_list", decode.list(decode.string))
decode.success(foo.Foo(a_bool, b_int, c_float, d_two_tuple, e_option_int, f_string_list))
}
pub fn from_string(json_str: String) {
json.parse(json_str, get_decoder_foo())
}