aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_json_ffi.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gleam_json_ffi.erl')
-rw-r--r--src/gleam_json_ffi.erl12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/gleam_json_ffi.erl b/src/gleam_json_ffi.erl
index c33f87f..2bfd6c6 100644
--- a/src/gleam_json_ffi.erl
+++ b/src/gleam_json_ffi.erl
@@ -6,7 +6,17 @@
]).
decode(Json) ->
- thoas:decode(Json).
+ try
+ {ok, json:decode(Json)}
+ catch
+ error:unexpected_end -> {error, unexpected_end_of_input};
+ error:{invalid_byte, Byte} -> {error, {unexpected_byte, hex(Byte)}};
+ error:{unexpected_sequence, Byte} -> {error, {unexpected_sequence, Byte}}
+ end.
+
+hex(I) ->
+ H = list_to_binary(integer_to_list(I, 16)),
+ <<"0x"/utf8, H/binary>>.
json_to_iodata(Json) ->
Json.