-module(claude_json_ffi). -export([json_string_to_raw/1, dynamic_to_json_string/1]). %% Parse a JSON string and embed it as raw iodata (gleam_json's Json type). %% gleam_json v3+ already requires OTP 27, so json:decode/encode are available. %% If parsing fails, encode the original string as a JSON string value so the %% error is visible downstream (e.g. the API will reject it with a useful message) %% rather than silently substituting an empty object. json_string_to_raw(JsonString) -> case gleam_json_ffi:decode(JsonString) of {ok, Decoded} -> json:encode(Decoded); {error, _} -> json:encode(JsonString) end. %% Re-encode an arbitrary Erlang term (from json:decode) back to a JSON string. dynamic_to_json_string(Term) -> iolist_to_binary(json:encode(Term)).