|
@@ -40,22 +40,30 @@
|
|
|
, decode/2
|
|
, decode/2
|
|
|
]}).
|
|
]}).
|
|
|
|
|
|
|
|
--spec(encode(jsx:json_term()) -> jsx:json_text()).
|
|
|
|
|
|
|
+-type(encode_options() :: jiffy:encode_options()).
|
|
|
|
|
+-type(decode_options() :: jiffy:decode_options()).
|
|
|
|
|
+
|
|
|
|
|
+-type(json_text() :: iolist() | binary()).
|
|
|
|
|
+-type(json_term() :: jiffy:jiffy_decode_result()).
|
|
|
|
|
+
|
|
|
|
|
+-export_type([json_text/0, json_term/0]).
|
|
|
|
|
+-export_type([decode_options/0, encode_options/0]).
|
|
|
|
|
+
|
|
|
|
|
+-spec(encode(json_term()) -> json_text()).
|
|
|
encode(Term) ->
|
|
encode(Term) ->
|
|
|
jsx:encode(Term).
|
|
jsx:encode(Term).
|
|
|
|
|
|
|
|
--spec(encode(jsx:json_term(), jsx_to_json:config())
|
|
|
|
|
- -> jsx:json_text()).
|
|
|
|
|
|
|
+-spec(encode(json_term(), encode_options()) -> json_text()).
|
|
|
encode(Term, Opts) ->
|
|
encode(Term, Opts) ->
|
|
|
jsx:encode(Term, Opts).
|
|
jsx:encode(Term, Opts).
|
|
|
|
|
|
|
|
--spec(safe_encode(jsx:json_term())
|
|
|
|
|
- -> {ok, jsx:json_text()} | {error, Reason :: term()}).
|
|
|
|
|
|
|
+-spec(safe_encode(json_term())
|
|
|
|
|
+ -> {ok, json_text()} | {error, Reason :: term()}).
|
|
|
safe_encode(Term) ->
|
|
safe_encode(Term) ->
|
|
|
safe_encode(Term, []).
|
|
safe_encode(Term, []).
|
|
|
|
|
|
|
|
--spec(safe_encode(jsx:json_term(), jsx_to_json:config())
|
|
|
|
|
- -> {ok, jsx:json_text()} | {error, Reason :: term()}).
|
|
|
|
|
|
|
+-spec(safe_encode(json_term(), encode_options())
|
|
|
|
|
+ -> {ok, json_text()} | {error, Reason :: term()}).
|
|
|
safe_encode(Term, Opts) ->
|
|
safe_encode(Term, Opts) ->
|
|
|
try encode(Term, Opts) of
|
|
try encode(Term, Opts) of
|
|
|
Json -> {ok, Json}
|
|
Json -> {ok, Json}
|
|
@@ -64,22 +72,21 @@ safe_encode(Term, Opts) ->
|
|
|
{error, Reason}
|
|
{error, Reason}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
--spec(decode(jsx:json_text()) -> jsx:json_term()).
|
|
|
|
|
|
|
+-spec(decode(json_text()) -> json_term()).
|
|
|
decode(Json) ->
|
|
decode(Json) ->
|
|
|
- jsx:decode(Json).
|
|
|
|
|
|
|
+ case jsx:decode(Json) of {Term} -> Term; Other -> Other end.
|
|
|
|
|
|
|
|
--spec(decode(jsx:json_text(), jsx_to_json:config())
|
|
|
|
|
- -> jsx:json_term()).
|
|
|
|
|
|
|
+-spec(decode(json_text(), decode_options()) -> json_term()).
|
|
|
decode(Json, Opts) ->
|
|
decode(Json, Opts) ->
|
|
|
- jsx:decode(Json, Opts).
|
|
|
|
|
|
|
+ case jsx:decode(Json, Opts) of {Term} -> Term; Other -> Other end.
|
|
|
|
|
|
|
|
--spec(safe_decode(jsx:json_text())
|
|
|
|
|
- -> {ok, jsx:json_term()} | {error, Reason :: term()}).
|
|
|
|
|
|
|
+-spec(safe_decode(json_text())
|
|
|
|
|
+ -> {ok, json_term()} | {error, Reason :: term()}).
|
|
|
safe_decode(Json) ->
|
|
safe_decode(Json) ->
|
|
|
safe_decode(Json, []).
|
|
safe_decode(Json, []).
|
|
|
|
|
|
|
|
--spec(safe_decode(jsx:json_text(), jsx_to_json:config())
|
|
|
|
|
- -> {ok, jsx:json_term()} | {error, Reason :: term()}).
|
|
|
|
|
|
|
+-spec(safe_decode(json_text(), decode_options())
|
|
|
|
|
+ -> {ok, json_term()} | {error, Reason :: term()}).
|
|
|
safe_decode(Json, Opts) ->
|
|
safe_decode(Json, Opts) ->
|
|
|
try decode(Json, Opts) of
|
|
try decode(Json, Opts) of
|
|
|
Term -> {ok, Term}
|
|
Term -> {ok, Term}
|