PL/SQL newbie here.
I am using Oracle APEX as my REST server and I am sending a JSON array (items) from my app to the REST server. The JSON contains logs, of which there could be 100s. I can send them successfully one by one, but that's not efficient so I want to be able to send a JSON array containing the logs instead.
Here is some test JSON:
{
"items": [{
"source": "00000999",
"message": "test1"
}, {
"source": "00000999",
"message": "test2"
}, {
"source": "00000999",
"message": "test3"
}, {
"source": "00000999",
"message": "test4"
}]
}
Once I can parse that JSON array, I will then be adding them to the database as separate rows.
Here is what I have at the moment:
set serveroutput on;
declare
items varchar2(2000):= '{"items":[{"source": "00000999","message": "test1"}, {"source": "00000999","message": "test2"}, {"source": "00000999","message": "test3"}, {"source": "00000999","message": "test4"}]}';
v_source varchar2(100);
v_message varchar2(2000);
v_json_list json_list;
v_json_list2 json_list;
begin
v_json_list := json_list(items);
v_json_list2 := json_ext.get_string(json(v_json_list.GET(0)),'items');
for i in 1..v_json_list2.count
loop
begin
v_source := json_ext.get_string(json(v_json_list2.GET(i)),'source');
v_message := json_ext.get_string(json(v_json_list2.GET(i)),'message');
ca_log_pak.log_info(v_source, v_message);
end;
end loop;
commit;
dbms_output.put_line('Y');
exception
when others then
dbms_output.put_line(SQLERRM);
end;
This is throwing an error saying expression is of the wrong type on v_json_list := json_list(items);
Can someone show me how to parse the items array properly?
Thanks