I have to parse a array of string in my JSON with ORACLE dans PLJSON module. I'm able to parse data without array like CLE,X,Y.. But when I want to get COLORS or REGROUPEMENT_COLORS, this return me nothing.
There is the code:
DECLARE
obj json := json();
obj_1 json := json();
arr json_list := json_list();
test varchar2(255);
BEGIN
obj := json('{
"DASHBOARD": {
"userUid": "",
"DATA_DASHBOARD": [
{
"CLE": "TESTTEST",
"X": "",
"Y": "",
"COL": "",
"ROW": "",
"CLASSCOLOR": "",
"COLORS": ["df","df"],
"REGROUPEMENT_ID": "",
"REGROUPEMENT_TEXT": "",
"REGROUPEMENT_CLASSCOLOR": "",
"REGROUPEMENT_X": "",
"REGROUPEMENT_Y": "",
"REGROUPEMENT_COL": "",
"REGROUPEMENT_ROW": "",
"REGROUPEMENT_COLORS": ["d","df"]
}
]
}
}');
obj_1 :=json(obj.get('DASHBOARD'));
arr := json_list(obj_1.get('DATA_DASHBOARD'));
test := json_ext.get_string(json(arr.get(1)), 'REGROUPEMENT_COLORS');
DBMS(test);
END;
Thanks !
REGROUPEMENT_COLORSis an array, not a string, sojson_ext.get_string()is not returning anything. If you want a string then getREGROUPEMENT_COLORS[1]orREGROUPEMENT_COLORS[2]; if you want the array then usejson_ext.get_json_listrather thanjson_ext.get_string.To output a string use
DBMS_OUTPUT.PUT_LINEnotDBMS.If you are using
json_extthen you can use the full path.PL/SQL:
(Note: the objects/packages have the
plprefix as db<>fiddle does not allow creating synonyms; you should be able to remove those prefixes if your implementation has the appropriate synonyms created.)Outputs:
db<>fiddle here