Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

problems Moving From APEX_JSON to JSON_OBJECT_T

user5979508Feb 3 2025 — edited Feb 6 2025
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

This post has been answered by Steve Muench-Oracle on Feb 3 2025
Jump to Answer
Comments
Post Details
Added on Feb 3 2025
3 comments
70 views