DECLARE
l_json json_object_t;
v_content CLOB;
BEGIN
APEX_JSON.initialize_clob_output;
apex_json.open_object;
apex_json.write('1', '£'); -- {"1":"\u00A3"}
apex_json.close_object;
v_content := APEX_JSON.get_clob_output;
dbms_output.put_line(v_content);
l_json := json_object_t();
l_json.PUT('2', '£'); -- {"2":"£"}
v_content := l_json.to_clob;
dbms_output.put_line(v_content);
l_json := json_object_t();
l_json.PUT('3', '\\u00A3'); -- {"3":"\\\\u00A3"}
v_content := l_json.to_clob;
dbms_output.put_line(v_content);
l_json := json_object_t();
l_json.PUT('4', APEX_ESCAPE.JSON('£')); -- {"4":"\\u00A3"}
v_content := l_json.to_clob;
dbms_output.put_line(v_content);
END;
select APEX_ESCAPE.JSON('£') from dual -- \u00A3
When using json_object_t with 2 byte characters the encoding to JSON does not escape the characters as apex_json does.
As scenario 1 and 2 show above.
And in trying to escape the characters manually (ie scenario 3) the escape character itself does not seem to be escapable as the documentation claims.
Is there any way to escape the input to json_object_t
to achieve the same escaping as apex_json.
I have REST calls failing with unescaped characters, making the move to json_object_t hard.
And this is the recommended way to avoid the JSON.WRITER.NOT_OPEN when using apex_json in PL/SQL code initiated by APEX