|
On May 31, 2018, at 10:50 AM, Jim L. Bostwick <jlbostwick@xxxxxxxxxxxxxxxxxx> wrote:
I am processing a JSON document using YAJLINTO but the data structure is not being populated. JSONFile is the IFS file I am processing, which looks like this:
{"InboundMessagesResult":{"ErrorCode":1000,"Message":"Invalid security token"}}
Dcl-Ds Results Qualified Inz;
numMessagesSentResult Int(10);
Dcl-Ds MessagesSentResult;
Result Ind;
ErrorCode Zoned(5:0);
Message VarChar(300);
Dcl-Ds Response LikeDs(Response_T) Dim(9999);
numResponse Int(10);
End-Ds;
End-Ds;
options = 'doc=file allowextra=yes countprefix=num case=any ';
Monitor;
Data-Into Results %Data(%Trim(JSONFile): %Trim(options))
%Parser('YAJL/YAJLINTO':
'{"value_true": "1", +
"value_false": "0", +
"value_null": " "}');
On-Error;
SyDsMsg.MsgDta = 'Error parsing ' + %TrimR(JSONFile);
Error = *On;
EndMon;
Normally, there is an array of results returned, but if there are errors only a portion of the expected JSON is returned. I have set the QIBM_RPG_DATA_INTO_TRACE_PARSER environment variable so that I can see what the parser is doing.
The trace looks like this:
---------------- Start ---------------
Data length 158 bytes
Data CCSID 13488
Converting data to UTF-8
Allocating YAJL stream parser
Parsing JSON data (yajl_parse)
No name provided for struct, assuming name of RPG variable
StartStruct
ReportName: 'InboundMessagesResult'
StartStruct
ReportName: 'ErrorCode'
ReportValue: '1000'
ReportName: 'Message'
ReportValue: 'Invalid security token'
EndStruct
EndStruct
YAJL parser status 0 after 79 bytes
YAJL parser final status: 0
---------------- Finish --------------
Not sure what I am doing wrong. The code makes it through the Monitor block OK but I was expecting that the Results.MessagesSentResult.Result indicator would be set, and that the
Results.MessagesSentResult.Message field would have data in it, however none of the parsed data is there.
Jim Bostwick
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.