diff --git a/src/jsx.erl b/src/jsx.erl index 88775ff..33e09d1 100644 --- a/src/jsx.erl +++ b/src/jsx.erl @@ -110,25 +110,30 @@ term_to_json(JSON, Opts) -> 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, []). --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) -> 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, []). --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) -> jsx_format:format(JSON, Opts). diff --git a/src/jsx_verify.erl b/src/jsx_verify.erl index 192102f..bff3636 100644 --- a/src/jsx_verify.erl +++ b/src/jsx_verify.erl @@ -34,11 +34,15 @@ -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. is_json(JSON, OptsList) when is_binary(JSON) -> P = jsx:decoder(extract_parser_opts(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) -> Opts = parse_opts(OptsList, #verify_opts{}), case Opts#verify_opts.naked_values of @@ -222,7 +226,18 @@ naked_value_test_() -> ) =:= false ) } - ]. + ]. + +terms_test_() -> + [ + {"terms", + ?_assert(is_json([start_object, + {key, "key"}, + {string, "value"}, + end_object + ], []) =:= true + )} + ]. -endif.