is_json inputs now line up with format inputs
This commit is contained in:
parent
fd3c6af50b
commit
e7025efe50
2 changed files with 25 additions and 5 deletions
13
src/jsx.erl
13
src/jsx.erl
|
@ -110,25 +110,30 @@ term_to_json(JSON, Opts) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
-spec is_json(JSON::binary()) -> true | false.
|
-spec is_json(JSON::binary()) -> true | false
|
||||||
|
; (Terms::list(jsx_encodeable())) -> true | false.
|
||||||
|
|
||||||
is_json(JSON) ->
|
is_json(JSON) ->
|
||||||
is_json(JSON, []).
|
is_json(JSON, []).
|
||||||
|
|
||||||
|
|
||||||
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false.
|
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false
|
||||||
|
; (Terms::list(jsx_encodeable()), Opts::verify_opts()) -> true | false.
|
||||||
|
|
||||||
is_json(JSON, Opts) ->
|
is_json(JSON, Opts) ->
|
||||||
jsx_verify:is_json(JSON, Opts).
|
jsx_verify:is_json(JSON, Opts).
|
||||||
|
|
||||||
|
|
||||||
-spec format(JSON::binary()) -> binary() | iolist().
|
-spec format(JSON::binary()) -> binary() | iolist()
|
||||||
|
; (Terms::list(jsx_encodeable())) -> binary() | iolist().
|
||||||
|
|
||||||
format(JSON) ->
|
format(JSON) ->
|
||||||
format(JSON, []).
|
format(JSON, []).
|
||||||
|
|
||||||
|
|
||||||
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist().
|
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist()
|
||||||
|
; (Terms::list(jsx_encodeable()), Opts::format_opts()) ->
|
||||||
|
binary() | iolist().
|
||||||
|
|
||||||
format(JSON, Opts) ->
|
format(JSON, Opts) ->
|
||||||
jsx_format:format(JSON, Opts).
|
jsx_format:format(JSON, Opts).
|
||||||
|
|
|
@ -34,11 +34,15 @@
|
||||||
|
|
||||||
|
|
||||||
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false
|
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false
|
||||||
|
; (Terms::list(jsx_encodeable()), Opts::verify_opts()) -> true | false
|
||||||
; (F::jsx_iterator(), Opts::verify_opts()) -> true | false.
|
; (F::jsx_iterator(), Opts::verify_opts()) -> true | false.
|
||||||
|
|
||||||
is_json(JSON, OptsList) when is_binary(JSON) ->
|
is_json(JSON, OptsList) when is_binary(JSON) ->
|
||||||
P = jsx:decoder(extract_parser_opts(OptsList)),
|
P = jsx:decoder(extract_parser_opts(OptsList)),
|
||||||
is_json(fun() -> P(JSON) end, OptsList);
|
is_json(fun() -> P(JSON) end, OptsList);
|
||||||
|
is_json(Terms, OptsList) when is_list(Terms) ->
|
||||||
|
P = jsx:encoder(),
|
||||||
|
is_json(fun() -> P(Terms) end, OptsList);
|
||||||
is_json(F, OptsList) when is_function(F) ->
|
is_json(F, OptsList) when is_function(F) ->
|
||||||
Opts = parse_opts(OptsList, #verify_opts{}),
|
Opts = parse_opts(OptsList, #verify_opts{}),
|
||||||
case Opts#verify_opts.naked_values of
|
case Opts#verify_opts.naked_values of
|
||||||
|
@ -222,7 +226,18 @@ naked_value_test_() ->
|
||||||
) =:= false
|
) =:= false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
terms_test_() ->
|
||||||
|
[
|
||||||
|
{"terms",
|
||||||
|
?_assert(is_json([start_object,
|
||||||
|
{key, "key"},
|
||||||
|
{string, "value"},
|
||||||
|
end_object
|
||||||
|
], []) =:= true
|
||||||
|
)}
|
||||||
|
].
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue