Page 1 of 1

Data-Into Issues

Posted: Tue Sep 28, 2021 4:38 pm
by kathan.p@gmail.com
JSON Code -

Code: Select all

{
  "trip_id": "16854-210922-47336",
  "cruise_control_set_speed": 67.7,
  "odometer": 59409.71,
  "heading": 1,
  "hard_brake_pre_wheel_speed": null,
  "post_event_data": {
    "logged_at": "2021-09-22T17:03:07.000Z",
    "location": {
      "latitude": 29.246766,
      "description": "5 mi NW of Ocala, FL",
      "longitude": -82.189743,
      "relative_position": {
        "country_code": "US",
        "distance": "5",
        "city": "Ocala",
        "unit_of_measure": "mi",
        "state_code": "FL",
        "direction": "NW"
      }
    }
  },
  "brake_position": 0,
  "road_curvature": -0.01,
  "parking_brake_status": "NA",
  "trigger": "Forward Collision Imminent Warning",
  "cruise_control_active": false,
  "accelerator_pedal": 100,
  "speed": 66.55,
  "hard_brake_post_wheel_speed": null,
  "event_id": "CE-16854-210922-FT-002",
  "logged_at": "2021-09-22T17:01:04.000Z",
  "abs_status": "NA",
  "heartbeat_id": "200000000000024900",
  "location": {
    "latitude": 29.214662,
    "description": "3 mi WNW of Ocala, FL",
    "longitude": -82.184375,
    "relative_position": {
      "country_code": "US",
      "distance": "3",
      "city": "Ocala",
      "unit_of_measure": "mi",
      "state_code": "FL",
      "direction": "WNW"
    }
  },
  "event": "follow_time_violation",
  "ignition": true,
  "cms_follow_time": 1.7
}
RPGLE Free Format Code -

Code: Select all

dcl-ds json qualified;                          
  dcl-subf trip_id char(18);                    
  dcl-subf cruise_control_set_speed char(4);    
  dcl-subf odometer zoned(11:0);                
  dcl-subf heading char(1);                     
  dcl-subf hard_brake_pre_wheel_speed char(5);  
        dcl-ds post_event_data;                     
                dcl-subf logged_at char(26);              
                     dcl-ds location ;                        
                          dcl-subf latitude char(10);             
                          dcl-subf description char(30);          
                          dcl-subf logitude char(10);             
                     dcl-ds relative_position;              
                            dcl-subf country_code char(2);       
                           dcl-subf distance char(5);           
                           dcl-subf city char(20);              
                           dcl-subf unit_of_measure char(2);    
                          dcl-subf state_code char(2);         
                         dcl-subf directon char(2);           
                     end-ds;                                
               end-ds;                                  
          end-ds;                                     
      dcl-subf brake_position char(2);              
    dcl-subf road_curvature char(5);    
    dcl-subf parking_brake_status char(2);               
   dcl-subf trigger char(50);                           
   dcl-subf accelerator_pedal char(3);                  
   dcl-subf hard_brake_post_wheel_speed char(3);        
  dcl-subf event_id char(30);                            
  dcl-subf logged_at char(26);                         
  dcl-subf ab_status char(10);                           
  dcl-subf heartbeat_id char(30);                      
  dcl-ds location;                                   
   dcl-subf latitude char(10);                       
   dcl-subf description char(30);                    
   dcl-subf logitude char(10);                       
    dcl-ds relative_position;                        
      dcl-subf country_code char(2);                 
      dcl-subf distance char(5);                     
      dcl-subf city char(20);                        
      dcl-subf unit_of_measure char(2);              
      dcl-subf state_code char(2);                   
      dcl-subf directon char(2);                     
    end-ds;                                          
  end-ds;                                            
dcl-subf event char(20);                             
dcl-subf ignition char(10);                          
  dcl-subf cms_follow_time char(5); 
end-ds;

Data-into json %Data(JsonString:'doc=string case=convert') %PARSER('YAJLINTO');                                   
I am getting any error that json.post_event_data.location not a valid /not mapped correctly...

Please advise

Re: Data-Into Issues

Posted: Tue Sep 28, 2021 5:42 pm
by brianjgarland
Is it because latitude and longitude are numeric in the JSON but you have them defined as character in your DS?

Re: Data-Into Issues

Posted: Wed Sep 29, 2021 12:43 pm
by Scott Klement
It does not matter if the data type is character or numeric for data-into. (It would with data-gen, however.)

But there are several problems with the data structure:
  1. You have "logitude" instead of LONGITUDE in two places.
  2. You have "directon" instead of DIRECTION in two places.
  3. You are missing the CRUISE_CONTROL_ACTIVE field.
  4. You are missing the SPEED field.
  5. You are missing the ABS_STATUS field.
As a reminder, you can put your JSON in a file in the IFS, and run the YAJLGEN command to generate an example of a data structure that works. It might not know the data types, or lengths of all of the fields, and won't know the maximum lengths of arrays. But, it will generate the correct field names in the correct place.

You can generate one and compare it to what you have in order to help you find problems like these.

Re: Data-Into Issues

Posted: Wed Sep 29, 2021 6:24 pm
by kathan.p@gmail.com
it worked! Thanks!!

I used YAJLGEN and it showed me exactly what i need. Thanks