is_json/2 and format/2 now both accept either a json text (binary) or a function that acts as a jsx iterator. specs updated to reflect
This commit is contained in:
parent
e088c6fd26
commit
0052480652
3 changed files with 38 additions and 32 deletions
|
@ -31,19 +31,17 @@
|
|||
-include("jsx_common.hrl").
|
||||
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-endif.
|
||||
|
||||
|
||||
|
||||
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false.
|
||||
|
||||
is_json(JSON, Opts) ->
|
||||
P = jsx:decoder(extract_parser_opts(Opts)),
|
||||
case proplists:get_value(strict, Opts, false) of
|
||||
true -> collect_strict(P(JSON), [[]])
|
||||
; false -> collect(P(JSON), [[]])
|
||||
|
||||
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false
|
||||
; (F::jsx_iterator(), Opts::verify_opts()) -> true | false.
|
||||
|
||||
is_json(JSON, OptsList) when is_binary(JSON) ->
|
||||
P = jsx:decoder(extract_parser_opts(OptsList)),
|
||||
is_json(fun() -> P(JSON) end, OptsList);
|
||||
is_json(F, OptsList) when is_function(F) ->
|
||||
case proplists:get_value(strict, OptsList, false) of
|
||||
true -> collect_strict(F(), [[]])
|
||||
; false -> collect(F(), [[]])
|
||||
end.
|
||||
|
||||
|
||||
|
@ -107,6 +105,7 @@ collect(_, _) ->
|
|||
|
||||
%% eunit tests
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
true_test_() ->
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue