sponsored links

Collapse

Announcement

Collapse
No announcement yet.

help on YAJL/YAJLINTO

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • help on YAJL/YAJLINTO

    HI all,
    I'm trying to use the YAJLINTO service program, but I'm doing something wrong.

    Here's a code sample:

    Code:
    **Free                                                                                 
    
    Ctl-Opt DftActGrp(*No) ActGrp('QILE')                                                  
            BndDir( 'YAJL/YAJL')                                          
            DatFmt(*Iso) TimFmt(*Iso)                                                      
            Alwnull(*UsrCtl)                                                               
            DecEdit('0.')                                                                  
            DftName(TESTJSON)                                                             
            Option(*SrcStmt:*NoDebugIo :*NoUnRef)                                          
            Debug;                                                                         
    
    dcl-s  jsondata  char(1000) inz('+                                                     
     {"Reqid":2,"client":"abc","array1":[{"order":1,"qta":1,"Price":550}],"array2":[]}');                                                                                 
    
    Dcl-Ds  TestJ Qualified  ;               
      num_Array1      Int(10) ;              
      num_Array2      Int(10) ;              
      ReqId             Int(10) ;            
      Client            Char(5)  ;           
      Dcl-Ds Array1     Dim(3)  ;            
        Order           Int(10)  ;           
        Qta             Int(10) ;            
        Price           Packed(15 :5) ;  
      End-Ds Array1;                         
      Dcl-Ds Array2     Dim(3)  ;            
        field1          Char(6)  ;           
        field2          Int(10) ;                           
      End-Ds Array2;                         
    End-Ds;                                  
    
    dcl-ds *N psds;              
      count Int(20) Pos(372);    
    end-ds;                      
    
    clear TestJ ;                                                                                      
    DATA-INTO TestJ  %Data(jsonData:                            
                          'case=convert doc=string countprefix=num_ allowmissing=yes allowextra=yes' )                          
                  %Parser('YAJL/YAJLINTO' );                                                        
    
    
    *InLR = *On;
    My problem is that I have to parse a JSon with two array, but sometimes one of these arrays is empty, in these case the value of Num_Array1 is 0 instead of 1.

    What I'm doing wrong?

    Many thanks.

    Bye


  • #2
    It seems to be a bug in DATA-INTO, or maybe YAJLINTO, not sure which without looking deeper.

    The problem is providing array2 as just [] -- i.e. you have an array, but it has no elements in it. This seems to cause DATA-INTO to go haywire.

    This will work as expected since there is no array2:
    Code:
    {"Reqid":2,"client":"abc","array1":[{"order":1,"qta":1,"Price":550}]}
    In that case, num_array1 is set to 1, and num_array2 is set to 0, as expected. But when you pass "array2": [], it causes countprefix to fail.

    Comment


    • #3
      There was a bug in the RPG compiler such that empty arrays were not reported correctly. There is a PTF out but I don't have it on my machine and don't have time to load it right now but it may be connected. See http://www-01.ibm.com/support/docvie...id=nas3SI68421 for details. It is not your exact case but may be related.

      I do see that if you completely remove the array2 entry the array1 count is returned correctly.

      Comment


      • #4
        Good find, Jon!

        I installed the 7.2 version of that same PTF ( http://www-01.ibm.com/support/docvie...id=nas3SI68422 ) and this solved the problem for me.

        Comment


        • #5
          Glad to hear it - I wasn't sure it would work as the description implied that empty arrays were causing DATA-INTO to fail (as opposed to fail to work properly)

          Comment


          • #6
            Hi JonBoy,

            Many thanks for your help, I installed the PTF and now it works!

            Many thanks too to Scott Klement for your parser!!!

            Bye

            Comment

            sponsored links

            Collapse

            Working...
            X