Trying to read the JSON payload (sent through web service/API) in ILE RPG using below logic, but ends up in error while invoking it through PostMan:
Error message – “'json parse: lexical error: invalid char in json text”
Could you please help to understand what am I missing here?
Let me know if you need further information.
Thank you!
Input Payload:
Code: Select all
{
"Header":[
{
"TransactionID":"123456",
"AccountNumber":87654321
}
],
"Detail":[
{
"TransactionType":"P",
"AccountType":"J",
"Contact":[
{
"ContactIndex":"DELIVERY",
"ContactGroupNum":1,
},
{
"ContactIndex":"DELIVERY",
"ContactGroupNum":2,
}
],
"ChangeUser":"UPDUSER"
}
]
}
Code snippet to retrieve the payload:
Code: Select all
Dcl-Proc GetJSONDocument;
Dcl-PI *N Ind;
Customer LikeDS(customer_T);
DocNode Like(yajl_val);
End-PI;
Dcl-DS ErrorCode;
*n int(10) inz(0);
*n int(10) inz(0);
End-DS;
Dcl-PR getenv pointer extproc(*dclcase);
var pointer value options(*string);
End-PR;
Dcl-S contentLength Int(10);
Dcl-S fd Int(10);
Dcl-S inpBuf Pointer;
Dcl-S inpLength Int(10);
Dcl-S outBuf Char(65535) Based(p);
Dcl-S p Pointer;
Dcl-C O_WRONLY 2;
Dcl-C O_TEXTDATA 16777216;
DocNode = yajl_stdin_load_tree(*On: ErrMsg);
If ErrMsg <> '';
Customer.HttpStatus = 500;
Customer.ErrorMsg = 'json parse: ' + errMsg;
Customer.Success = *off;
EndIf;
Code: Select all
Dcl-DS header_t qualified template;
TransactionID char(50) inz(' ');
AccountNumber zoned(8) inz;
End-DS;
Dcl-DS contact_t qualified template;
ContactIndex char(15) inz('');
ContactGroupNum zoned(5) inz;
End-DS;
Dcl-DS detail_t qualified template;
TransactionType char(1) inz(' ');
AccountType char(1) inz(' ');
Contact likeds(Contact_t) dim(999) inz(*likeds);
ChangeUser char(10) inz(' ');
End-DS;
Dcl-DS customer_t qualified template;
success ind inz(*on);
httpStatus packed(3) inz(0);
errorMsg varchar(500) inz('');
header likeds(header_t) inz(*likeds);
detail likeds(detail_t) inz(*likeds);
End-DS;
Dcl-DS Customer likeds(Customer_t) inz(*likeds);