Current section
Files
Jump to
Current section
Files
src/decoder.erl
-module(decoder).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/decoder.gleam").
-export([glee_parse_json_string/2, glee_parse_json_float/2, glee_parse_json_int/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/decoder.gleam", 6).
?DOC(
" Parse a JSON string and return\n"
" the string value of a given field.\n"
).
-spec glee_parse_json_string(binary(), binary()) -> {ok, binary()} |
{error, binary()}.
glee_parse_json_string(Json, Field) ->
Json_decoder = begin
gleam@dynamic@decode:field(
Field,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Json@1) -> gleam@dynamic@decode:success(Json@1) end
)
end,
Json_result = begin
_pipe = Json,
gleam@json:parse(_pipe, Json_decoder)
end,
case Json_result of
{ok, Json_result@1} ->
{ok, Json_result@1};
{error, _} ->
{error, <<"Failed to parse string"/utf8>>}
end.
-file("src/decoder.gleam", 27).
?DOC(
" Parse a JSON string and return\n"
" the float value of a given field.\n"
).
-spec glee_parse_json_float(binary(), binary()) -> {ok, float()} |
{error, binary()}.
glee_parse_json_float(Json, Field) ->
Json_decoder = begin
gleam@dynamic@decode:field(
Field,
{decoder, fun gleam@dynamic@decode:decode_float/1},
fun(Json@1) -> gleam@dynamic@decode:success(Json@1) end
)
end,
Json_result = begin
_pipe = Json,
gleam@json:parse(_pipe, Json_decoder)
end,
case Json_result of
{ok, Value} ->
{ok, Value};
{error, _} ->
{error, <<"Failed to parse float"/utf8>>}
end.
-file("src/decoder.gleam", 48).
?DOC(
" Parse a JSON string and return\n"
" the int value of a given field.\n"
).
-spec glee_parse_json_int(binary(), binary()) -> {ok, integer()} |
{error, binary()}.
glee_parse_json_int(Json, Field) ->
Json_decoder = begin
gleam@dynamic@decode:field(
Field,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Json@1) -> gleam@dynamic@decode:success(Json@1) end
)
end,
Json_result = begin
_pipe = Json,
gleam@json:parse(_pipe, Json_decoder)
end,
case Json_result of
{ok, Value} ->
{ok, Value};
{error, _} ->
{error, <<"Failed to parse integer"/utf8>>}
end.