Reading JSON Problem(s)

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: Reading JSON Problem(s)

Post by emhill »

Ok... made the changes to the field names. Getting another error:

Code: Select all

                         Additional Message Information                        
                                                                               
 Message ID . . . . . . :   RNX0356       Severity . . . . . . . :   50        
 Message type . . . . . :   Escape                                             
 Date sent  . . . . . . :   08/04/21      Time sent  . . . . . . :   16:31:42  
                                                                               
 Message . . . . :   The document for the DATA-INTO operation does not match   
   the RPG variable; reason code 5.                                            
 Cause . . . . . :   While parsing a document for the DATA-INTO operation, the 
   parser found that the document does not correspond to RPG variable          
   "allresponse" and the options do not allow for this. The reason code is 5.  
   The exact subfield for which the error was detected is                      
   "allresponse.batchclaimresponse(1).claiminfo". The options are "doc=file    
   case=any". The document name is /eric/4WARD/Claim Submit Response Test.json;
   *N indicates that the document is not an external file. The parser is       
   'YAJL/YAJLINTO'. *N indicates that the parser is a procedure pointer.       
Here is my updated RPG. Note that the first data structure is called allresponse. Should this be something different? I've looked at the spelling of everything else and unless I missed something it all seems to match the JSON file:

Code: Select all

**free                                                    
 ctl-opt dftactgrp(*no) debug option(*srcstmt:*nodebugio);
 ctl-opt bnddir('QC2LE':'YAJL');                          
                                                          
 dcl-ds allresponse qualified;                            
    status char(20);                                      
    message char(60);                                     
    interfaceName char(80);                               
    dcl-ds batchClaimResponse dim(150);                   
       businessPartnerCode char(10);                      
          dcl-ds claimInfo;                               
             claimNumber char(20);                        
             trackNumber char(10);                        
             repairingOutlet char(10);                    
             repairOrder# char(6);                        
             serialNumber char(10);                       
             submittalIndicator char(1);                  
             dateTimeProcessed char(23);                  
             claimStatusCode char(3);                     
             claimStatusDescription char(80);             
             dispositionCode char(10);                    
             dispositionCodeDescription char(80);         
             rmaStatusCode  char(3);                      
             rmaStatusDescription  char(80);              
             approvedDollarAmount char(15);               
             identifier char(10);                         
          end-ds;                                         
          dcl-ds claimProcessMsgInfo dim(300);            
             lineNumber char(10);                         
             processCode char(4);                         
             processCategoryDescription char(25);         
             processMessage char(80);                     
          end-ds;                                         
       end-ds;                                            
    end-ds;                                               
                                                          
    dcl-s jsonpath varchar(150)                           
       inz('/eric/4WARD/Claim Submit Response Test.json');
                                                          
    data-into allresponse %data(jsonpath:                 
                          'doc=file case=any')            
                          %Parser('YAJL/YAJLINTO');       
                                                          
    *inlr = *on;                                          
Scott Klement
Site Admin
Posts: 669
Joined: Sun Jul 04, 2021 5:12 am

Re: Reading JSON Problem(s)

Post by Scott Klement »

Hi Eric,
  1. You have 'trackNumber' but the JSON says 'trackingNumber'
  2. You have listed 150 'batchClaimResponse' elements (via DIM(150)) however, the JSON only has one.
  3. You have listed 300 'claimProcessMsgInfo' elements, but the JSON only has two.
  4. Your 'claimProcessMsgInfo' structure is directly inside 'batchClaimResponse', but in the JSON it is inside 'claimInfo'.
To fix 2 & 3, above, you'll need to use countprefix so that RPG can notify you of how many elements are in the particular arrays.

Don't forget, you can use YAJLGEN to generate an example structure if you need it. It won't know the maximum size of your strings or arrays -- so the code you hand-wrote is probably much better -- but it can figure out the basic structure of the document, which can be very helpful when you're stucking figuring out why you keep getting 'REASON 5' errors.
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: Reading JSON Problem(s)

Post by emhill »

This is why I come here!!! :)

Thanks for the YAJLGEN suggestion. That works great!

Can you elaborate on the countprefix a little or point me to a good article that discusses it? I'll search as well.

Thanks!!!
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: Reading JSON Problem(s)

Post by emhill »

Scott,

Nevermind! I think I got it now. Thanks for all the assistance....
Post Reply