Current section
Files
Jump to
Current section
Files
src/jackson@internal@encoder.erl
-module(jackson@internal@encoder).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_string_builder/1, to_string/1]).
-spec to_string_builder(jackson@internal@json:json()) -> gleam@string_builder:string_builder().
to_string_builder(Json) ->
case Json of
null ->
gleam@string_builder:from_string(<<"null"/utf8>>);
{float, Inner} ->
_pipe = gleam@float:to_string(Inner),
gleam@string_builder:from_string(_pipe);
{integer, Inner@1} ->
_pipe@1 = gleam@int:to_string(Inner@1),
gleam@string_builder:from_string(_pipe@1);
{bool, true} ->
gleam@string_builder:from_string(<<"true"/utf8>>);
{bool, false} ->
gleam@string_builder:from_string(<<"false"/utf8>>);
{string, Inner@2} ->
_pipe@2 = gleam@string_builder:from_string(
jackson@internal@escaping:escape_string(Inner@2)
),
_pipe@3 = gleam@string_builder:prepend(_pipe@2, <<"\""/utf8>>),
gleam@string_builder:append(_pipe@3, <<"\""/utf8>>);
{array, Entries} ->
_pipe@4 = gleam@list:map(Entries, fun to_string_builder/1),
_pipe@7 = gleam@list:index_fold(
_pipe@4,
gleam@string_builder:new(),
fun(Acc, Builder, Idx) ->
Term_prepend = case Idx of
0 ->
<<""/utf8>>;
_ ->
<<","/utf8>>
end,
_pipe@5 = Acc,
_pipe@6 = gleam@string_builder:append(_pipe@5, Term_prepend),
gleam@string_builder:append_builder(_pipe@6, Builder)
end
),
_pipe@8 = gleam@string_builder:prepend(_pipe@7, <<"["/utf8>>),
gleam@string_builder:append(_pipe@8, <<"]"/utf8>>);
{object, Entries@1} ->
_pipe@11 = gleam@list:map(
Entries@1,
fun(Entry) ->
_pipe@9 = to_string_builder(
{string, erlang:element(1, Entry)}
),
_pipe@10 = gleam@string_builder:append(
_pipe@9,
<<":"/utf8>>
),
gleam@string_builder:append_builder(
_pipe@10,
to_string_builder(erlang:element(2, Entry))
)
end
),
_pipe@14 = gleam@list:index_fold(
_pipe@11,
gleam@string_builder:new(),
fun(Acc@1, Builder@1, Idx@1) ->
Term_prepend@1 = case Idx@1 of
0 ->
<<""/utf8>>;
_ ->
<<","/utf8>>
end,
_pipe@12 = Acc@1,
_pipe@13 = gleam@string_builder:append(
_pipe@12,
Term_prepend@1
),
gleam@string_builder:append_builder(_pipe@13, Builder@1)
end
),
_pipe@15 = gleam@string_builder:prepend(_pipe@14, <<"{"/utf8>>),
gleam@string_builder:append(_pipe@15, <<"}"/utf8>>)
end.
-spec to_string(jackson@internal@json:json()) -> binary().
to_string(Json) ->
_pipe = to_string_builder(Json),
gleam@string_builder:to_string(_pipe).