-module(sara@json). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/sara/json.gleam"). -export([json_serializable_builder/1]). -export_type([generated_code/0, custom_encoder/0, custom_decoder/0, custom_zero_value/0, custom_codec/0, config/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " JSON Serialization Code Generator\n" "\n" " This module provides a builder that automatically generates JSON encoding\n" " and decoding functions for Gleam custom types annotated with `//@json_encode`\n" " and/or `//@json_decode`.\n" "\n" " ## Basic Usage\n" "\n" " Annotate your types:\n" "\n" " ```gleam\n" " //@json_encode\n" " //@json_decode\n" " pub type User {\n" " User(name: String, age: Int)\n" " }\n" " ```\n" "\n" " This generates a companion `*_json.gleam` file containing:\n" " - `pub fn user_to_json(user: User) -> json.Json`\n" " - `pub fn user_json_decoder() -> decode.Decoder(User)`\n" "\n" " ## Custom Codecs\n" "\n" " For types requiring special serialization logic, provide a `CustomCodec`:\n" "\n" " ```gleam\n" " json.json_serializable_builder(\n" " json.Config([\n" " json.CustomCodec(\n" " type_name: \"Timestamp\",\n" " module_path: \"gleam/time/timestamp\",\n" " encode: fn(_, _, variable, _, _) {\n" " json.GeneratedCode(\n" " \"json.string(timestamp.to_rfc3339(\" <> variable <> \", calendar.utc_offset))\",\n" " [\"gleam/time/calendar\", \"gleam/time/timestamp\"],\n" " [],\n" " )\n" " },\n" " decode: fn(_, _, _, _) {\n" " json.GeneratedCode(\n" " \"{\n" " use date <- decode.then(decode.string)\n" " case timestamp.parse_rfc3339(date) {\n" " Ok(timestamp) -> decode.success(timestamp)\n" " Error(_) -> decode.failure(timestamp.system_time(), \\\"Timestamp\\\")\n" " }\n" " }\",\n" " [\"gleam/time/calendar\", \"gleam/time/timestamp\"],\n" " [],\n" " )\n" " },\n" " zero: fn(_, _, _, _) {\n" " Ok(json.GeneratedCode(\"timestamp.system_time()\", [\"gleam/time/timestamp\"], []))\n" " },\n" " ),\n" " ]),\n" " )\n" " ```\n" "\n" " ## Codec Resolution Order\n" "\n" " 1. **Built-in types**: `Int`, `Float`, `Bool`, `String`, `List`, tuples\n" " 2. **Custom codecs**: Types registered via `CustomCodec` in config\n" " 3. **Annotated types**: Types with `//@json_encode` or `//@json_decode`\n" " 4. **Fallback**: Unresolved types become function parameters\n" "\n" ). -type generated_code() :: {generated_code, binary(), list(binary()), list({binary(), binary()})}. -type custom_encoder() :: {custom_encoder, binary(), binary(), fun((builder@context:build_context(), glance:type(), binary(), builder@module:module_(), builder@module:module_()) -> generated_code())}. -type custom_decoder() :: {custom_decoder, binary(), binary(), fun((builder@context:build_context(), glance:type(), builder@module:module_(), builder@module:module_()) -> generated_code())}. -type custom_zero_value() :: {custom_zero_value, binary(), binary(), fun((builder@context:build_context(), glance:type(), builder@module:module_(), builder@module:module_()) -> {ok, generated_code()} | {error, nil})}. -type custom_codec() :: {custom_codec, binary(), binary(), fun((builder@context:build_context(), glance:type(), binary(), builder@module:module_(), builder@module:module_()) -> generated_code()), fun((builder@context:build_context(), glance:type(), builder@module:module_(), builder@module:module_()) -> generated_code()), fun((builder@context:build_context(), glance:type(), builder@module:module_(), builder@module:module_()) -> {ok, generated_code()} | {error, nil})}. -type config() :: {config, list(custom_codec())}. -file("src/sara/json.gleam", 222). -spec get_generated_module_name(binary()) -> binary(). get_generated_module_name(Path) -> <>. -file("src/sara/json.gleam", 1441). -spec virtual_type_definition( {ok, builder@inspect:type_definition()} | {error, nil}, builder@context:build_context(), glance:type(), builder@module:module_() ) -> {ok, builder@inspect:type_definition()} | {error, nil}. virtual_type_definition(Result, Ctx, Type_, Current_module) -> case Result of {ok, _} -> Result; {error, _} -> case Type_ of {named_type, _, Name, Module, _} -> Is_prelude = builder@inspect:is_prelude_type( Ctx, Type_, Current_module ), case {Name, Module, Is_prelude} of {<<"Result"/utf8>>, none, true} -> {ok, {custom_type, {definition, [], {custom_type, {span, 0, 0}, <<"Result"/utf8>>, public, false, [<<"a"/utf8>>, <<"b"/utf8>>], [{variant, <<"Ok"/utf8>>, [{unlabelled_variant_field, {variable_type, {span, 0, 0}, <<"a"/utf8>>}}], []}, {variant, <<"Error"/utf8>>, [{unlabelled_variant_field, {variable_type, {span, 0, 0}, <<"b"/utf8>>}}], []}]}}, {module, <<""/utf8>>, erlang:element(3, Current_module), erlang:element(4, Current_module), erlang:element(5, Current_module), erlang:element(6, Current_module), erlang:element(7, Current_module), erlang:element(8, Current_module), erlang:element(9, Current_module), erlang:element(10, Current_module), erlang:element(11, Current_module)}}}; {_, _, _} -> Result end; _ -> Result end end. -file("src/sara/json.gleam", 1501). -spec module_name_for_path(binary()) -> binary(). module_name_for_path(Name) -> case Name of <<""/utf8>> -> <<""/utf8>>; _ -> <> end. -file("src/sara/json.gleam", 1010). -spec json_decode_type_generic( config(), builder@context:build_context(), glance:type(), builder@module:module_(), builder@module:module_(), gleam@set:set(glance:custom_type()) ) -> generated_code(). json_decode_type_generic( Config, Ctx, Type_, Current_module, Original_module, Custom_type_path ) -> case virtual_type_definition( builder@inspect:find_type_definition(Ctx, Type_, Current_module), Ctx, Type_, Current_module ) of {ok, Type_defintion} -> case Type_defintion of {type_alias, Source, Module} -> json_decode_type( Config, Ctx, erlang:element(6, erlang:element(3, Source)), Module, Original_module, Custom_type_path ); {custom_type, Source@1, Module@1} -> Custom_decoders = [{custom_decoder, <<"Option"/utf8>>, <<"gleam/option"/utf8>>, fun(_, _, _, _) -> Parameters@1 = case Type_ of {named_type, _, _, _, Parameters} -> Parameters; _assert_fail -> erlang:error( #{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"sara/json"/utf8>>, function => <<"json_decode_type_generic"/utf8>>, line => 1043, value => _assert_fail, start => 28628, 'end' => 28680, pattern_start => 28639, pattern_end => 28672} ) end, Type_@2 = case Parameters@1 of [Type_@1 | _] -> Type_@1; _assert_fail@1 -> erlang:error( #{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"sara/json"/utf8>>, function => <<"json_decode_type_generic"/utf8>>, line => 1044, value => _assert_fail@1, start => 28697, 'end' => 28732, pattern_start => 28708, pattern_end => 28719} ) end, Code = json_decode_type( Config, Ctx, Type_@2, Current_module, Original_module, Custom_type_path ), {generated_code, <<<<"decode.optional("/utf8, (erlang:element(2, Code))/binary>>/binary, ")"/utf8>>, erlang:element(3, Code), erlang:element(4, Code)} end}], Decoder = gleam@list:find_map( lists:append( Custom_decoders, gleam@list:map( erlang:element(2, Config), fun(Codec) -> {custom_decoder, erlang:element(2, Codec), erlang:element(3, Codec), erlang:element(5, Codec)} end ) ), fun(Custom_decoder) -> case (erlang:element(3, erlang:element(3, Source@1)) =:= erlang:element(2, Custom_decoder)) andalso (erlang:element(4, Module@1) =:= erlang:element( 3, Custom_decoder )) of true -> {ok, erlang:element(4, Custom_decoder)}; _ -> {error, nil} end end ), case Decoder of {ok, Decode} -> Decode(Ctx, Type_, Current_module, Original_module); _ -> case builder@inspect:find_attribute( Source@1, <<"json_decode"/utf8>> ) of {ok, _} -> Other_arguments = case gleam@set:contains( Custom_type_path, erlang:element(3, Source@1) ) of false -> Custom_type_path@1 = gleam@set:insert( Custom_type_path, erlang:element(3, Source@1) ), erlang:element( 4, json_decode_custom_type( Config, Ctx, erlang:element(3, Source@1), Module@1, Custom_type_path@1 ) ); _ -> [] end, case erlang:element(4, Module@1) =:= erlang:element( 4, Original_module ) of true -> {generated_code, <<<<<<(justin:snake_case( erlang:element( 3, erlang:element( 3, Source@1 ) ) ))/binary, "_json_decoder("/utf8>>/binary, (begin _pipe = gleam@list:map( Other_arguments, fun(Argument) -> erlang:element( 1, Argument ) end ), _pipe@1 = gleam@list:unique( _pipe ), gleam@string:join( _pipe@1, <<","/utf8>> ) end)/binary>>/binary, ")"/utf8>>, [], Other_arguments}; false -> {generated_code, <<<<<<<<<<(get_generated_module_name( erlang:element( 2, Module@1 ) ))/binary, "."/utf8>>/binary, (justin:snake_case( erlang:element( 3, erlang:element( 3, Source@1 ) ) ))/binary>>/binary, "_json_decoder("/utf8>>/binary, (begin _pipe@2 = gleam@list:map( Other_arguments, fun(Argument@1) -> erlang:element( 1, Argument@1 ) end ), _pipe@3 = gleam@list:unique( _pipe@2 ), gleam@string:join( _pipe@3, <<","/utf8>> ) end)/binary>>/binary, ")"/utf8>>, [get_generated_module_name( erlang:element( 4, Module@1 ) )], Other_arguments} end; {error, _} -> Parameters@3 = case Type_ of {named_type, _, _, _, Parameters@2} -> Parameters@2; _ -> [] end, Function = <<<<(justin:snake_case( erlang:element( 3, erlang:element(3, Source@1) ) ))/binary, (case Parameters@3 of [] -> <<""/utf8>>; _ -> <<"_"/utf8, (begin _pipe@4 = gleam@list:map( Parameters@3, fun(Parameter) -> case Parameter of {named_type, _, Name, _, _} -> justin:snake_case( Name ); _ -> <<""/utf8>> end end ), gleam@string:join( _pipe@4, <<"_"/utf8>> ) end)/binary>> end)/binary>>/binary, "_json_decoder"/utf8>>, {generated_code, <>, [erlang:element(4, Module@1)], [{Function, <<<<<<<<"fn() -> decode.Decoder("/utf8, (module_name_for_path( erlang:element( 2, Module@1 ) ))/binary>>/binary, (erlang:element( 3, erlang:element( 3, Source@1 ) ))/binary>>/binary, (case Parameters@3 of [] -> <<""/utf8>>; _ -> <<<<"("/utf8, (begin _pipe@5 = gleam@list:map( Parameters@3, fun( Parameter@1 ) -> case Parameter@1 of {named_type, _, Name@1, _, _} -> Name@1; _ -> <<""/utf8>> end end ), gleam@string:join( _pipe@5, <<","/utf8>> ) end)/binary>>/binary, ")"/utf8>> end)/binary>>/binary, ")"/utf8>>}]} end end end; {error, _} -> Parameters@5 = case Type_ of {named_type, _, _, _, Parameters@4} -> Parameters@4; _ -> [] end, Function@1 = <<<<(justin:snake_case(case Type_ of {named_type, _, Name@2, _, _} -> Name@2; _ -> <<""/utf8>> end))/binary, (case Parameters@5 of [] -> <<""/utf8>>; _ -> <<"_"/utf8, (begin _pipe@6 = gleam@list:map( Parameters@5, fun(Parameter@2) -> case Parameter@2 of {named_type, _, Name@3, _, _} -> justin:snake_case(Name@3); _ -> <<""/utf8>> end end ), gleam@string:join(_pipe@6, <<"_"/utf8>>) end)/binary>> end)/binary>>/binary, "_json_decoder"/utf8>>, {generated_code, <>, [], [{Function@1, <<""/utf8>>}]} end. -file("src/sara/json.gleam", 745). -spec json_decode_custom_type( config(), builder@context:build_context(), glance:custom_type(), builder@module:module_(), gleam@set:set(glance:custom_type()) ) -> generated_code(). json_decode_custom_type(Config, Ctx, Custom_type, Module, Custom_type_path) -> Has_variant_type = case erlang:element(7, Custom_type) of [_] -> false; _ -> true end, Variants = gleam@list:map( erlang:element(7, Custom_type), fun(Variant) -> json_decode_variant( Config, Ctx, Variant, Has_variant_type, Module, Custom_type_path ) end ), Output@5 = case Has_variant_type of true -> Output = <<"use variant <- decode.field(\"type\", decode.string)\n"/utf8>>, Output@1 = <>, Output@2 = < erlang:element(2, Variant@1) end ), gleam@string:join(_pipe@1, <<"\n"/utf8>>) end)/binary>>, Zero_value = gleam@list:find_map( erlang:element(7, Custom_type), fun(Variant@2) -> get_variant_zero_value( Config, Ctx, Variant@2, Module, gleam@set:new() ) end ), Output@3 = <<<<<<<<< decode.failure("/utf8>>/binary, (case Zero_value of {ok, Zero_value@1} -> erlang:element(2, Zero_value@1); _ -> <<(justin:snake_case( erlang:element(3, Custom_type) ))/binary, "_zero_value"/utf8>> end)/binary>>/binary, ", \""/utf8>>/binary, (erlang:element(3, Custom_type))/binary>>/binary, "\" )\n"/utf8>>, Output@4 = <>, {generated_code, Output@4, [], case Zero_value of {ok, _} -> []; _ -> [{<<(justin:snake_case(erlang:element(3, Custom_type)))/binary, "_zero_value"/utf8>>, <<(module_name_for_path( erlang:element(2, Module) ))/binary, (erlang:element(3, Custom_type))/binary>>}] end}; false -> {generated_code, begin _pipe@2 = Variants, _pipe@3 = gleam@list:map( _pipe@2, fun(Variant@3) -> erlang:element(2, Variant@3) end ), gleam@string:join(_pipe@3, <<"\n"/utf8>>) end, [], []} end, {generated_code, erlang:element(2, Output@5), begin _pipe@4 = gleam@list:map( Variants, fun(Variant@4) -> erlang:element(3, Variant@4) end ), _pipe@5 = gleam@list:fold( _pipe@4, [], fun(Acc, Imports) -> lists:append(Acc, Imports) end ), lists:append(_pipe@5, erlang:element(3, Output@5)) end, begin _pipe@6 = gleam@list:map( Variants, fun(Variant@5) -> erlang:element(4, Variant@5) end ), _pipe@7 = gleam@list:fold( _pipe@6, [], fun(Acc@1, Arguments) -> lists:append(Acc@1, Arguments) end ), lists:append(_pipe@7, erlang:element(4, Output@5)) end}. -file("src/sara/json.gleam", 830). -spec json_decode_variant( config(), builder@context:build_context(), glance:variant(), boolean(), builder@module:module_(), gleam@set:set(glance:custom_type()) ) -> generated_code(). json_decode_variant( Config, Ctx, Variant, Has_variant_type, Module, Custom_type_path ) -> Output = <<""/utf8>>, Fields = gleam@list:index_map( erlang:element(3, Variant), fun(Field, I) -> Variable = case Field of {labelled_variant_field, _, Label} -> Label; {unlabelled_variant_field, _} -> <<"field"/utf8, (erlang:integer_to_binary(I))/binary>> end, case erlang:element(2, Field) of {variable_type, _, _} -> {generated_code, <<"todo as \"cant handle generic\""/utf8>>, [], []}; _ -> {generated_code, Code, Imports, Arguments} = json_decode_type( Config, Ctx, erlang:element(2, Field), Module, Module, Custom_type_path ), {generated_code, <<<<<<<<<<<<"use "/utf8, Variable/binary>>/binary, "<- decode.field(\""/utf8>>/binary, Variable/binary>>/binary, "\","/utf8>>/binary, Code/binary>>/binary, ")\n"/utf8>>, Imports, Arguments} end end ), Output@1 = < erlang:element(2, Field@1) end ), gleam@string:join(_pipe@1, <<""/utf8>>) end)/binary>>, Output@2 = <<<<<<<<<>/binary, (module_name_for_path(erlang:element(2, Module)))/binary>>/binary, (erlang:element(2, Variant))/binary>>/binary, (case gleam@list:is_empty(erlang:element(3, Variant)) of false -> Parameters = begin _pipe@2 = gleam@list:index_map( erlang:element(3, Variant), fun(Field@2, I@1) -> case Field@2 of {labelled_variant_field, _, Label@1} -> <>; {unlabelled_variant_field, _} -> <<"field"/utf8, (erlang:integer_to_binary(I@1))/binary>> end end ), gleam@string:join(_pipe@2, <<","/utf8>>) end, <<<<"("/utf8, Parameters/binary>>/binary, ")"/utf8>>; _ -> <<""/utf8>> end)/binary>>/binary, ")"/utf8>>, {generated_code, case Has_variant_type of true -> <<<<<<<<"\""/utf8, (justin:snake_case(erlang:element(2, Variant)))/binary>>/binary, "\"-> {"/utf8>>/binary, Output@2/binary>>/binary, "}"/utf8>>; false -> Output@2 end, begin _pipe@3 = gleam@list:map( Fields, fun(Field@3) -> erlang:element(3, Field@3) end ), gleam@list:fold( _pipe@3, [], fun(Acc, Imports@1) -> lists:append(Acc, Imports@1) end ) end, begin _pipe@4 = gleam@list:map( Fields, fun(Field@4) -> erlang:element(4, Field@4) end ), gleam@list:fold( _pipe@4, [], fun(Acc@1, Arguments@1) -> lists:append(Acc@1, Arguments@1) end ) end}. -file("src/sara/json.gleam", 918). -spec json_decode_type( config(), builder@context:build_context(), glance:type(), builder@module:module_(), builder@module:module_(), gleam@set:set(glance:custom_type()) ) -> generated_code(). json_decode_type( Config, Ctx, Type_, Current_module, Original_module, Custom_type_path ) -> Is_prelude = builder@inspect:is_prelude_type(Ctx, Type_, Current_module), case Type_ of {named_type, _, Name, _, Parameters} -> case {Name, Is_prelude} of {<<"Int"/utf8>>, true} -> {generated_code, <<"decode.int"/utf8>>, [], []}; {<<"Float"/utf8>>, true} -> {generated_code, <<"decode.one_of(decode.float, [decode.map(decode.int, int.to_float)])"/utf8>>, [<<"gleam/int"/utf8>>], []}; {<<"Bool"/utf8>>, true} -> {generated_code, <<"decode.bool"/utf8>>, [], []}; {<<"String"/utf8>>, true} -> {generated_code, <<"decode.string"/utf8>>, [], []}; {<<"List"/utf8>>, true} -> Type_@2 = case Parameters of [Type_@1 | _] -> Type_@1; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"sara/json"/utf8>>, function => <<"json_decode_type"/utf8>>, line => 941, value => _assert_fail, start => 25947, 'end' => 25982, pattern_start => 25958, pattern_end => 25969}) end, List_decoder = json_decode_type( Config, Ctx, Type_@2, Current_module, Original_module, Custom_type_path ), {generated_code, <<<<"decode.list("/utf8, ((erlang:element(2, List_decoder)))/binary>>/binary, ")"/utf8>>, erlang:element(3, List_decoder), erlang:element(4, List_decoder)}; {_, _} -> json_decode_type_generic( Config, Ctx, Type_, Current_module, Original_module, Custom_type_path ) end; {tuple_type, _, Elements} -> Codes = gleam@list:map( Elements, fun(Element) -> json_decode_type( Config, Ctx, Element, Current_module, Original_module, Custom_type_path ) end ), {generated_code, <<<<<<<<<<"{"/utf8, (begin _pipe = Codes, _pipe@1 = gleam@list:index_map( _pipe, fun(Code, I) -> <<<<<<<<<<<<"use "/utf8, ((<<"field"/utf8, (erlang:integer_to_binary( I ))/binary>>))/binary>>/binary, " <- decode.field("/utf8>>/binary, (erlang:integer_to_binary( I ))/binary>>/binary, ","/utf8>>/binary, (erlang:element(2, Code))/binary>>/binary, ")"/utf8>> end ), gleam@string:join( _pipe@1, <<"\n"/utf8>> ) end)/binary>>/binary, "decode.success(#("/utf8>>/binary, (begin _pipe@2 = Codes, _pipe@3 = gleam@list:index_map( _pipe@2, fun(_, I@1) -> <<"field"/utf8, (erlang:integer_to_binary(I@1))/binary>> end ), gleam@string:join(_pipe@3, <<","/utf8>>) end)/binary>>/binary, "))"/utf8>>/binary, "}"/utf8>>, begin _pipe@4 = gleam@list:map( Codes, fun(Code@1) -> erlang:element(3, Code@1) end ), gleam@list:fold( _pipe@4, [], fun(Acc, Imports) -> lists:append(Acc, Imports) end ) end, begin _pipe@5 = gleam@list:map( Codes, fun(Code@2) -> erlang:element(4, Code@2) end ), gleam@list:fold( _pipe@5, [], fun(Acc@1, Arguments) -> lists:append(Acc@1, Arguments) end ) end}; _ -> {generated_code, <<"todo"/utf8>>, [], []} end. -file("src/sara/json.gleam", 712). -spec json_create_custom_type_decode_function( config(), builder@context:build_context(), glance:custom_type(), builder@module:module_() ) -> generated_code(). json_create_custom_type_decode_function(Config, Ctx, Custom_type, Module) -> X = justin:snake_case(erlang:element(3, Custom_type)), {generated_code, Code, Imports, Arguments} = json_decode_custom_type( Config, Ctx, Custom_type, Module, gleam@set:new() ), Output = <<<<<<<<<<<<<<"pub fn "/utf8, X/binary>>/binary, "_json_decoder("/utf8>>/binary, (begin _pipe = gleam@list:map( Arguments, fun(Argument) -> case erlang:element(2, Argument) of <<""/utf8>> -> erlang:element(1, Argument); _ -> <<<<(erlang:element(1, Argument))/binary, ":"/utf8>>/binary, (erlang:element(2, Argument))/binary>> end end ), _pipe@1 = gleam@list:unique(_pipe), gleam@string:join(_pipe@1, <<","/utf8>>) end)/binary>>/binary, ") -> decode.Decoder("/utf8>>/binary, (module_name_for_path(erlang:element(2, Module)))/binary>>/binary, (erlang:element(3, Custom_type))/binary>>/binary, ") {\n"/utf8>>, Output@1 = <>, Output@2 = <>, {generated_code, Output@2, Imports, Arguments}. -file("src/sara/json.gleam", 1355). -spec get_zero_value_generic( config(), builder@context:build_context(), glance:type(), builder@module:module_(), builder@module:module_(), gleam@set:set(glance:variant()) ) -> {ok, generated_code()} | {error, nil}. get_zero_value_generic( Config, Ctx, Type_, Current_module, Original_module, Variant_path ) -> case virtual_type_definition( builder@inspect:find_type_definition(Ctx, Type_, Current_module), Ctx, Type_, Current_module ) of {ok, Type_defintion} -> case Type_defintion of {type_alias, Source, Module} -> get_zero_value( Config, Ctx, erlang:element(6, erlang:element(3, Source)), Module, Original_module, Variant_path ); {custom_type, Source@1, Module@1} -> Custom_zero_values = [{custom_zero_value, <<"Option"/utf8>>, <<"gleam/option"/utf8>>, fun(_, _, _, _) -> {ok, {generated_code, <<"option.None"/utf8>>, [<<"gleam/option"/utf8>>], []}} end}], Decoder = gleam@list:find_map( lists:append( Custom_zero_values, gleam@list:map( erlang:element(2, Config), fun(Codec) -> {custom_zero_value, erlang:element(2, Codec), erlang:element(3, Codec), erlang:element(6, Codec)} end ) ), fun(Custom_decoder) -> case (erlang:element(3, erlang:element(3, Source@1)) =:= erlang:element(2, Custom_decoder)) andalso (erlang:element(4, Module@1) =:= erlang:element( 3, Custom_decoder )) of true -> {ok, erlang:element(4, Custom_decoder)}; _ -> {error, nil} end end ), case Decoder of {ok, Decode} -> Decode(Ctx, Type_, Current_module, Original_module); _ -> case erlang:element(5, erlang:element(3, Source@1)) of true -> {error, nil}; _ -> gleam@list:find_map( erlang:element( 7, erlang:element(3, Source@1) ), fun(Variant) -> get_variant_zero_value( Config, Ctx, Variant, Module@1, Variant_path ) end ) end end end; {error, _} -> {error, nil} end. -file("src/sara/json.gleam", 1220). -spec get_variant_zero_value( config(), builder@context:build_context(), glance:variant(), builder@module:module_(), gleam@set:set(glance:variant()) ) -> {ok, generated_code()} | {error, nil}. get_variant_zero_value(Config, Ctx, Variant, Module, Variant_path) -> gleam@bool:guard( gleam@set:contains(Variant_path, Variant), {error, nil}, fun() -> Variant_path@1 = gleam@set:insert(Variant_path, Variant), Output = <<""/utf8>>, Fields = gleam@list:try_map( erlang:element(3, Variant), fun(Field) -> case erlang:element(2, Field) of {variable_type, _, _} -> {error, nil}; _ -> Zero = get_zero_value( Config, Ctx, erlang:element(2, Field), Module, Module, Variant_path@1 ), case Zero of {ok, Zero@1} -> {ok, {generated_code, <<(case Field of {labelled_variant_field, _, Label} -> <