Page 1 of 1

JSON array without a named tag

Posted: Thu May 30, 2024 7:56 am
by AddiedePinho
The JSON received does not have a named tag for the arrays "properties"

there are no key value pairs in the properties list.
How do i need to setup my data structure to handle this?


this is the input (oRestExp.Response)

Code: Select all

{
    "id": "6655d1976079af00011c931b",
    "isBankAccountValid": true,
    "bankAccount": {
        "failedValidations": [],
        "properties": [
            "ACCOUNT_ACCEPTS_CREDITS",
            "ACCOUNT_ACCEPTS_DEBITS",
            "ACCOUNT_OLDER_THAN_THREE_MONTHS"
        ]
    },
    "bankAccountHolder": {
        "failedValidations": [
            "FAMILY_NAME_MISMATCH"
        ]
    }
}

Code: Select all

dcl-ds VerifyResponse  qualified;             
   id                    char(100);           
   isBankAccountValid    ind;                 
   dcl-ds bankAccount;                        
      num_failedValidations  int(10);         
      dcl-ds  failedValidations  dim(10);     
      end-ds;                                 
      num_properties        int(10);          
      dcl-ds properties  dim(10);             
      end-ds;                                 
   end-ds;                                    
   dcl-ds bankAccountHolder;                  
      num_failedValidations int(10);          
      dcl-ds failedValidations  dim(10);      
      end-ds;                                 
   end-ds;                                    
end-ds;      

data-into VerifyResponse %DATA(oRestExp.Response:     
                  'case=convert +                     
                  allowmissing=yes +                  
                  allowextra=yes +                    
                  countprefix=num_')                  
                  %PARSER('YAJLINTO');                   


the output VerifyResponse:
VERIFYRESPONSE.ID =
....5...10...15...20...25...30...35...40...45...50...55...60
1 '6655d1976079af00011c931b '
61 ' '
VERIFYRESPONSE.ISBANKACCOUNTVALID = '1'
VERIFYRESPONSE.BANKACCOUNT.NUM_FAILEDVALIDATIONS = 1077952576
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(1) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(2) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(3) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(4) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(5) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(6) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(7) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(8) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(9) = ' '
VERIFYRESPONSE.BANKACCOUNT.FAILEDVALIDATIONS(10) = ' '
VERIFYRESPONSE.BANKACCOUNT.NUM_PROPERTIES = 1077952576
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(1) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(2) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(3) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(4) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(5) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(6) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(7) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(8) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(9) = ' '
VERIFYRESPONSE.BANKACCOUNT.PROPERTIES(10) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.NUM_FAILEDVALIDATIONS = 1077952576
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(1) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(2) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(3) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(4) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(5) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(6) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(7) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(8) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(9) = ' '
VERIFYRESPONSE.BANKACCOUNTHOLDER.FAILEDVALIDATIONS(10) = ' '

Re: JSON array without a named tag

Posted: Thu May 30, 2024 4:35 pm
by jonboy49
Don't have time to play with this - supposed to be on vacation ...

At first glance "properties" should just be an array not a DS.

So this:

Code: Select all

     num_properties        int(10);          
     properties   varchar(50)   dim(10);    

Re: JSON array without a named tag

Posted: Thu May 30, 2024 8:50 pm
by Scott Klement
both properties and failedValidations should be arrays of character strings, not arrays of data structures.

Re: JSON array without a named tag

Posted: Thu Jun 06, 2024 8:28 am
by AddiedePinho
Thank you for the reply.
I made the change, and it works