From 37f5581958b5dd49913834703b09805cc7aad33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Caama=C3=B1o=20Souto?= Date: Tue, 28 May 2024 13:17:09 +0200 Subject: [PATCH] doc(#18): update README --- README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1e0d093..62d7863 100644 --- a/README.md +++ b/README.md @@ -48,18 +48,35 @@ Add `njson` to your project dependencies. %%% Decode 1> njson:decode(<<"{\"a\":\"b\"}">>). -{ok,#{<<"a">> => <<"b">>},<<>>} +{ok,#{<<"a">> => <<"b">>}} %%% Encode as binary 2> njson:encode(#{<<"a">> => <<"b">>}). -<<"{\"a\":\"b\"}">> +{ok,<<"{\"a\":\"b\"}">>} %%% Encode as iolist (even faster) 3> njson:encode(#{<<"a">> => <<"b">>}, true). -[123,[[34,<<"a">>,34],58,[34,<<"b">>,34]],125] +{ok,[123,[[34,<<"a">>,34],58,[34,<<"b">>,34]],125]} ``` +## Error handling + +See [details](https://github.com/nomasystems/njson/blob/94c586b92a7e24c403089cdbe2994b7e7c87b9cc/src/njson.erl#L22) + +```erl + +%%% Decode + +1> njson:decode(<<"{\"a\":\"b\}">>). +{error,{unexpected_end_of_string,[],6}} + + +%%% Encode +2> njson:encode(#{<<"a">> => a}). +{error,{invalid_map,{<<"a">>,a,{invalid_value,a}}}} +``` + ## Benchmarks ```