#StackBounty: #oracle-11g #plsql #oracle-apex Changing a JSON object parsed with APEX_JSON

Bounty: 50

I would like to be able to change a JSON object parsed with the APEX_JSON.parse() function, but I found nothing in the official documentation, no tips or examples about that.

In the code below I putted comments in the specific points in order to give a clear idea about my need.

SET SERVEROUTPUT ON 

DECLARE
    j apex_json.t_values;
    l_paths apex_t_varchar2;    
    writers clob;
    json_object_result clob;
BEGIN

    writers := '[
        {
            "id": null,
            "hashCode": "7ef605fc8dba5425d6965fbd4c8fbe1f",
            "description": "Machado de Assis",
            "base64Img": "8eNZ28Dh5rZQIPhNEfwqoo1LCVx..."
        },
        {
            "id": 151,
            "hashCode": "a8f15eda80c50adb0e71943adc8015cf",
            "description": "José Alencar",
            "base64Img": "/XIQIHCol8eNZ28Dh5rZQIPhNEfwqoo1LCVx/9k=..."
        }
    ]';

    apex_json.parse(j, writers);

    l_paths := apex_json.find_paths_like (
        p_values         => j,
        p_return_path => '[%]',
        p_subpath       => '.hashCode',
        p_value    => '7ef605fc8dba5425d6965fbd4c8fbe1f'
    );

    dbms_output.put_line('Itens found: ' || l_paths.count);

    if (l_paths.count = 1) then 
        dbms_output.put_line('id: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.id'));
        dbms_output.put_line('hashCode: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.hashCode'));
        dbms_output.put_line('description: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.description'));
        dbms_output.put_line('base64Img: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.base64Img'));
--      Here I would like to nullify base64Img attribute value
        json_object_result := 'here goes the object matched in the search with the base64Img attribute value null';
    end if;

END;

In my json_object_result variable I would like to save the JSON object matched in the apex_json.find_paths_like() with its base64Img attribute null. In my example the result would be

{
"id": null,
"hashCode": "7ef605fc8dba5425d6965fbd4c8fbe1f",
"description": "Machado de Assis",
"base64Img": ""
}

or

{
"id": null,
"hashCode": "7ef605fc8dba5425d6965fbd4c8fbe1f",
"description": "Machado de Assis"
}

Is it possible to make something like that with APEX_JSON?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.