DATA-INTO to parse json response
Posted: Fri Feb 02, 2024 9:19 am
Hi All,
RPG code is receiving json response after invoking a rest api. I created the below data structure and used data-into to parse the response json. Success response works fine but receiving error for failed response. Could some help me with the solution.
*
dcl-ds Data qualified;
status char(25);
errmsg char(100);
dcl-ds invoiceData dim(1);
invoice char(10);
date char(10);
name char(30);
amount char(15);
end-ds;
responseCode char(3);
end-ds;
*
DATA-INTO epmData %DATA( json_ifs_res: 'doc=file +
case=any countprefix=num_') %PARSER('YAJLINTO');
*
The json response is as follows -
Success scenario response -
{
"status": "success",
"errmsg": "",
"data": [
{
"invoice": "13889",
"date": "02/01/2024",
"name": "Paper mate clear point",
"amount": 14.80,
}
],
"responseCode": "200"
}
*
Error Scenario response -
{
"status": "failed",
"errmsg": "Error Message Here",
"data": [ ],
"responseCode": "200"
}
RPG code is receiving json response after invoking a rest api. I created the below data structure and used data-into to parse the response json. Success response works fine but receiving error for failed response. Could some help me with the solution.
*
dcl-ds Data qualified;
status char(25);
errmsg char(100);
dcl-ds invoiceData dim(1);
invoice char(10);
date char(10);
name char(30);
amount char(15);
end-ds;
responseCode char(3);
end-ds;
*
DATA-INTO epmData %DATA( json_ifs_res: 'doc=file +
case=any countprefix=num_') %PARSER('YAJLINTO');
*
The json response is as follows -
Success scenario response -
{
"status": "success",
"errmsg": "",
"data": [
{
"invoice": "13889",
"date": "02/01/2024",
"name": "Paper mate clear point",
"amount": 14.80,
}
],
"responseCode": "200"
}
*
Error Scenario response -
{
"status": "failed",
"errmsg": "Error Message Here",
"data": [ ],
"responseCode": "200"
}