Error when using YAJLINTO

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/
Post Reply
juan11de14
Posts: 7
Joined: Mon May 08, 2023 3:50 pm

Error when using YAJLINTO

Post by juan11de14 »

Good morning,
I have been studying to use YAJL and I have created a REST(POST) service using the IWS example convertTemp, however I have not been able to retrieve the output JSON for reason code 5. Please help.


********************

Code: Select all

**free                                                                 
    ctl-opt option(*srcstmt) dftactGrp(*no) bnddir('HTTPAPI');         
    /copy httpapi_h                                                    
    dcl-s   HTTPCODE    char(100);                                     
    dcl-s   url         varchar(2000);                                 
    dcl-s   request     varchar(2000);                                 
    dcl-s   response    varchar(19);                                   
    dcl-s   httpstatus  int(10);                                       
    dcl-ds reqds qualified;                                            
      TEMPIN          varchar(10);                                     
    end-ds;                                                            
    dcl-ds result qualified;                                           
      TEMPOUT   varchar(10);                                           
    end-ds;                                                            
    reqds.TEMPIN = '87.21';                                            
    data-gen reqds %data(request) %gen('YAJLDTAGEN');                  
    http_debug(*on: '/tmp/watson-diagnostic-log.txt');                 
    url = 'http://10.14.36.24:10240/web/services/convertirTemperatura';
    monitor;                                                           
        response = http_string('POST': url: request: 'application/json'
        on-error;                                                      
        httpcode = http_error();                                       
    endmon;                                                            
    DATA-INTO result %DATA(response) %PARSER('YAJLINTO');              
    *InLr = *On;                                                       
                                                                       
**end-free    
****************************
el servicio retorna RESPONSE = '{"TEMPOUT":"30.67"}' pero se genera el erorr...

Code: Select all

                        Información Adicional de Mensaje                       
                                                                               
 ID de mensaje  . . . . :   RNX0356       Gravedad . . . . . . . :   50        
 Tipo de mensaje  . . . :   Diagnóstico                                        
 Fecha envío  . . . . . :   08/05/23      Hora envío . . . . . . :   10:56:20  
                                                                               
 Mensaje . . . . :   El documento de la operación DATA-INTO no coincide con la 
   variable RPG; el código de razón es 5.                                      
 Causa . . . . . :   Al analizar un documento para la operación DATA-INTO, el  
   analizador ha descubierto que el documento no se corresponde con la variable
   RPG "result" y las opciones no lo permiten. El código de razón es 5. El     
   subcampo exacto para el que se detectó el error es "result." Las opciones   
   son "*N/A*". El nombre del documento es *N; *N indica que el documento XML  
   no es un archivo externo. El analizador es 'YAJLINTO'. *N indica que el     
   analizador es un puntero de procedimiento.                                  
 Recuperación  . :   Póngase en contacto con el responsable de mantenimiento de
   programas para determinar la causa del problema.                            
 Descripción técnica . . . . . . . . . :   Los códigos de razón y los   
significados correspondientes son los siguientes:                           
.
.
.
5. El documento contiene nombres adicionales que no coinciden con los       
  subcampos.                                                                
.
.
.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Error when using YAJLINTO

Post by jonboy49 »

Are you actually getting a response? You have a monitor block in place to trap errors on the GET but you go ahead and use DATA-INTO regardless.

If you are receiving a response what does the json look like?
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Error when using YAJLINTO

Post by Scott Klement »

Isn't the IWS convertTemp a SOAP API? Did they make a REST version?

What does the data in 'response' look like?
juan11de14
Posts: 7
Joined: Mon May 08, 2023 3:50 pm

Re: Error when using YAJLINTO

Post by juan11de14 »

Yes, I am correctly receiving the JSON response and it is {"TEMPOUT":"30.67"}'
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Error when using YAJLINTO

Post by Scott Klement »

You'll need to add case=convert to DATA-INTO. (Otherwise, it will only recognize JSON fields that are all lowercase.)

Code: Select all

DATA-INTO result %DATA(response:'case=convert') %PARSER('YAJLINTO');
juan11de14
Posts: 7
Joined: Mon May 08, 2023 3:50 pm

Re: Error when using YAJLINTO

Post by juan11de14 »

Thank you very much Scott,
As an exercise, I have taken the same service program from the converttemp service and deployed it to REST (POST), I have already made the change and it works perfect. "DATA-INTO result %DATA(response:'case=convert') %PARSER('YAJLINTO')"
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Error when using YAJLINTO

Post by jonboy49 »

Scott Klement wrote: Mon May 08, 2023 7:53 pm Isn't the IWS convertTemp a SOAP API? Did they make a REST version?
REST option has been available for several years now Scott.
Post Reply