Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Json parse return empty in plsql

I ma using PLSQL. I have json. But when i parse the json, it retun empty. Here is the sample PLSQL code:

  CREATE OR REPLACE PROCEDURE my_process 
    IS
       myjson   VARCHAR2 (32767):= '{"responseinfo":"<TRANSACTION><RESPONSE_CODE>100</RESPONSE_CODE><RESPONSE_MSG>Duplicate Request Found.</RESPONSE_MSG></TRANSACTION>"}';
        l_json_obj    JSON_OBJECT_T;
        requestinfo   VARCHAR2 (32767);
    BEGIN
        BEGIN
        
            l_json_obj := JSON_OBJECT_T.parse (myjson);
            requestinfo := l_json_obj.get_string ('requestinfo');
        END;


    END;

When I want get requestinfo from json, it return empty. What is the wrong of my code.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your JSON has the key responseinfo and you are trying to get the value for requestinfo; you are not going to get the value because the two are different.

If you want responseinfo (and not requestinfo) then:

CREATE OR REPLACE PROCEDURE my_process 
IS
  myjson   VARCHAR2 (32767):= '{"responseinfo":"<TRANSACTION><RESPONSE_CODE>100</RESPONSE_CODE><RESPONSE_MSG>Duplicate Request Found.</RESPONSE_MSG></TRANSACTION>"}';
  l_json_obj    JSON_OBJECT_T;
  requestinfo   VARCHAR2 (32767);
BEGIN
  l_json_obj := JSON_OBJECT_T.parse (myjson);
  requestinfo := l_json_obj.get_string ('responseinfo');
  DBMS_OUTPUT.PUT_LINE(requestinfo);
END;
/

Outputs:

<TRANSACTION><RESPONSE_CODE>100</RESPONSE_CODE><RESPONSE_MSG>Duplicate Request Found.</RESPONSE_MSG></TRANSACTION>

If you do actually want requestinfo then that does not exist so a NULL response is valid.

fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading