diff options
author | Louis Pilfold <louis@lpil.uk> | 2024-05-23 19:02:55 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-05-23 19:32:48 +0100 |
commit | 1979919b792910e6c75f3e28596f017d980b45ee (patch) | |
tree | e59fae108e195b6edc22bfc13181b2e2dcd7cd59 /src/gleam_json_ffi.erl | |
parent | efe70ef04ae57bca78344cd13ccf4e40eac3ed21 (diff) | |
download | gleam_json-1979919b792910e6c75f3e28596f017d980b45ee.tar.gz gleam_json-1979919b792910e6c75f3e28596f017d980b45ee.zip |
Decoding
Diffstat (limited to 'src/gleam_json_ffi.erl')
-rw-r--r-- | src/gleam_json_ffi.erl | 12 |
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. |