Forum Stats

  • 3,768,282 Users
  • 2,252,770 Discussions
  • 7,874,514 Comments

Discussions

Question on JSON data

User_CI7SY
User_CI7SY Member Posts: 61 Green Ribbon

Hi Team, I have one json_array_t(variable =ARR) with value given below and I want to make one json data type(variable=FINAL_J) using this value and adding one key to the array .Could you please help me understand which json data type to be used here and how to create that? Will it be json_element_t?

ARR := JSON_ARRAY_T('[{"Address1":"3121,"Address2":"Suite 301"},{"Address1":"3121","Address2":"Suite 301"}]');

FINAL_J = '{"distributors":[{"Address1":"3121,"Address2":"Suite 301"},{"Address1":"3121","Address2":"Suite 301"}] }'

Answers

  • Solomon Yakobson
    Solomon Yakobson Member Posts: 18,908 Red Diamond
    edited Oct 16, 2021 10:38AM

    First of all there is a missing double quote after first 3121. Anyway:

    DECLARE
        ARR   JSON_ARRAY_T;
        FINAL_J JSON_OBJECT_T;
    BEGIN
        ARR := JSON_ARRAY_T('[{"Address1":"3121","Address2":"Suite 301"},{"Address1":"3121","Address2":"Suite 301"}]');
        FINAL_J := JSON_OBJECT_T();
        FINAL_J.PUT('distributors',ARR);
        DBMS_OUTPUT.PUT_LINE(FINAL_J.STRINGIFY);
    END;
    /
    
    {"distributors":[{"Address1":"3121","Address2":"Suite 301"},{"Address1":"3121","Address2":"Suite 301"}]}
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    SY.

  • User_CI7SY
    User_CI7SY Member Posts: 61 Green Ribbon

    Thanks , it worked.