JSON_EQUALS is not supported in PL/SQL expressions, and will throw that exception.
You can use it in SQL within PL/SQL, but it seems you have to do a few extra steps when you're starting from JSON_ARRAY_T and JSON_OBJECT_T.
If you have an array and an object declared something like:
declare
l_array json_array_t;
l_object json_object_t;
and populated from your HTTP call or manually, then you need string versions declared, with your object converted to a string once, and each array element also converted to a string as you loop over the array.
l_clob_1 := l_object.to_clob;
<<json_loop>>
for i in 0..l_array.get_size - 1 loop
l_clob_2 := l_array.get(i).to_clob;
You can then use a SQL query to call JSON_EQUAL using those strings:
select case when json_equal(l_clob_1, l_clob_2) then 1 else 0 end
into l_match_num
from dual;
You can then set your boolean flag, and break the loop, if that returns 1.
if l_match_num = 1 then
l_match_boo := true;
exit json_loop;
end if;
end loop;
You can then use that boolean value however you need to.
So putting that together as a demo with made-up data:
declare
l_array json_array_t;
l_object json_object_t;
l_clob_1 clob;
l_clob_2 clob;
l_match_num number;
l_match_boo boolean;
begin
l_array := json_array_t('[{"id": 1, "value":"hello"},{"id": 2, "value":"world"}]');
l_object := json_object_t('{"id": 2, "value":"world"}');
l_clob_1 := l_object.to_clob;
<<json_loop>>
for i in 0..l_array.get_size - 1 loop
l_clob_2 := l_array.get(i).to_clob;
select case when json_equal(l_clob_1, l_clob_2) then 1 else 0 end
into l_match_num
from dual;
if l_match_num = 1 then
dbms_output.put_line('Index ' || i || ' matched');
l_match_boo := true;
exit json_loop;
end if;
end loop;
if l_match_boo then
dbms_output.put_line('Match');
else
dbms_output.put_line('No match');
end if;
end;
/
which output:
Index 1 matched
Match
fiddle
The context switching will affect the efficiency but how much maybe depends on the amount of data. You could potentially convert the array to a temporary table of JSON strings and then query that in once go, rather than one element at a time, but that might end up being more work and less efficient.
I am getting a return of an array of JSON OBJECT from GET request from HTTP API endpoint
If you are actually getting a string and parsing that into a JSON_ARRAY_T then you can probably approach this completely differently by using other functions like JSON_TABLE to parse it instead, and then doing the entire parse/comparison in a single SQL query. You haven't shown what you're actually ding though, so that may not be possible.
JSON_EQUALSis not supported in PL/SQL expressions. But you should be able to use it in SQL within PL/SQL. A minimal reproducible example might be helpful.