aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_json_ffi.erl
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-05-23 19:02:55 +0100
committerLouis Pilfold <louis@lpil.uk>2024-05-23 19:32:48 +0100
commit1979919b792910e6c75f3e28596f017d980b45ee (patch)
treee59fae108e195b6edc22bfc13181b2e2dcd7cd59 /src/gleam_json_ffi.erl
parentefe70ef04ae57bca78344cd13ccf4e40eac3ed21 (diff)
downloadgleam_json-1979919b792910e6c75f3e28596f017d980b45ee.tar.gz
gleam_json-1979919b792910e6c75f3e28596f017d980b45ee.zip
Decoding
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.