-module(gleam@json). -compile(no_auto_import). -export([decode/1, to_string/1, to_string_builder/1, string/1, bool/1, int/1, float/1, null/0, nullable/2, object/1, array/2, preprocessed_array/1]). -export_type([json/0, decode_error/0]). -type json() :: any(). -type decode_error() :: unexpected_end_of_input | {unexpected_byte, binary(), integer()} | {unexpected_sequence, binary(), integer()}. -spec decode(binary()) -> {ok, gleam@dynamic:dynamic()} | {error, decode_error()}. decode(A) -> thoas:decode(A). -spec to_string(json()) -> binary(). to_string(A) -> gleam_json_ffi:json_to_string(A). -spec to_string_builder(json()) -> gleam@string_builder:string_builder(). to_string_builder(A) -> gleam_json_ffi:json_to_iodata(A). -spec string(binary()) -> json(). string(A) -> thoas_encode:string(A). -spec bool(boolean()) -> json(). bool(A) -> thoas_encode:boolean(A). -spec int(integer()) -> json(). int(A) -> thoas_encode:integer(A). -spec float(float()) -> json(). float(A) -> thoas_encode:float(A). -spec null() -> json(). null() -> thoas_encode:null(). -spec nullable(gleam@option:option(J), fun((J) -> json())) -> json(). nullable(Input, Inner_type) -> case Input of {some, Value} -> Inner_type(Value); none -> thoas_encode:null() end. -spec object(list({binary(), json()})) -> json(). object(A) -> thoas_encode:non_recursive_object(A). -spec array(list(M), fun((M) -> json())) -> json(). array(Entries, Inner_type) -> _pipe = Entries, _pipe@1 = gleam@list:map(_pipe, Inner_type), thoas_encode:non_recursive_array(_pipe@1). -spec preprocessed_array(list(json())) -> json(). preprocessed_array(A) -> thoas_encode:non_recursive_array(A).