DATA-INTO with YAJLINTO
Posted: Mon May 13, 2024 5:33 pm
I'm receiving JSON on a webservice call, that is written to a temporary file in the IFS. That file is then fed into an RPG data structure using DATA-INTO with YAJLINTO.
I believe the incoming data is causing a problem for the parser were it has an empty array named "pastFireOverview" (see below).
The RPG data structure and DATA-INTO command are very simple, defined as :
D List ds qualified
d riskScore 2a varying
d trackingid 32a varying
DATA-INTO List %Data( %trimr(Tempfile)
: 'doc=file case=any allowextra=yes')
%PARSER('YAJLINTO');
When the DATA-INTO command executes, no error is encountered but, whereas the riskScore variable is populated, the trackingId is not. Note that trackingId comes after the empty array variable in the incoming data. In fact if I change the RPG data structure to include other names found in the incoming data, any corresponding entity, that is located after the empty array, fails to map to the corresponding variable in the data structure. If I remove the empty "pastFireOverview" array from the incoming JSON, all data maps correctly.
Has anyone experienced this and if so, have you found a solution? I think it's unlikely that the webservice provider would be open to changing the content.
{"riskScore":66,"riskDescription":"Urban","riskLevel":1,"nearestHighRiskLevel":"746","nearestVeryHighRiskLevel":"5614","preburnRiskScore":-1,"preburnRiskDescription":"NA","preburnDistanceHigh":"NA","preburnDistanceVeryHigh":"NA","landUseDensityClass":"High Density Residential","landUseDensityLevel":2,"distanceWildlandFeet":1816,"avgDayHighWind":"2","recentlyBurned":"No","numFiresRecentYears":0,"pastFireOverview":[],"fuel":"The wildfire fuel on your property is considered low and does not pose a significant threat for wildfire","drought":"The drought conditions over the past 5 years are contributing to the wildfire threat at a high level at your location","wind":"The wind conditions in the areas that encompass your property over the last 5 years are contributing to the wildfire threat at a low level.","slope":"The slope associated with your property is not a factor in the wildfire threat.","aspect":"The aspect associated with your property is a factor in the wildfire threat.","distanceHighVeryHighFuels":"Wildfire fuels are in relatively close proximity to your location. As the distance to higher hazard wildfire fuel decreases, the threat of embers increases.","distanceWildland":"The distance from your property to surrounding large open areas that are not developed poses moderate wildfire threat. ","firebreakCategory":"The density of the structures in the area surrounding your property is high and is not a factor in the wildfire threat to this property. ","trackingId":"c71024af17b85203ab79dc94bdb81756"}
I believe the incoming data is causing a problem for the parser were it has an empty array named "pastFireOverview" (see below).
The RPG data structure and DATA-INTO command are very simple, defined as :
D List ds qualified
d riskScore 2a varying
d trackingid 32a varying
DATA-INTO List %Data( %trimr(Tempfile)
: 'doc=file case=any allowextra=yes')
%PARSER('YAJLINTO');
When the DATA-INTO command executes, no error is encountered but, whereas the riskScore variable is populated, the trackingId is not. Note that trackingId comes after the empty array variable in the incoming data. In fact if I change the RPG data structure to include other names found in the incoming data, any corresponding entity, that is located after the empty array, fails to map to the corresponding variable in the data structure. If I remove the empty "pastFireOverview" array from the incoming JSON, all data maps correctly.
Has anyone experienced this and if so, have you found a solution? I think it's unlikely that the webservice provider would be open to changing the content.
{"riskScore":66,"riskDescription":"Urban","riskLevel":1,"nearestHighRiskLevel":"746","nearestVeryHighRiskLevel":"5614","preburnRiskScore":-1,"preburnRiskDescription":"NA","preburnDistanceHigh":"NA","preburnDistanceVeryHigh":"NA","landUseDensityClass":"High Density Residential","landUseDensityLevel":2,"distanceWildlandFeet":1816,"avgDayHighWind":"2","recentlyBurned":"No","numFiresRecentYears":0,"pastFireOverview":[],"fuel":"The wildfire fuel on your property is considered low and does not pose a significant threat for wildfire","drought":"The drought conditions over the past 5 years are contributing to the wildfire threat at a high level at your location","wind":"The wind conditions in the areas that encompass your property over the last 5 years are contributing to the wildfire threat at a low level.","slope":"The slope associated with your property is not a factor in the wildfire threat.","aspect":"The aspect associated with your property is a factor in the wildfire threat.","distanceHighVeryHighFuels":"Wildfire fuels are in relatively close proximity to your location. As the distance to higher hazard wildfire fuel decreases, the threat of embers increases.","distanceWildland":"The distance from your property to surrounding large open areas that are not developed poses moderate wildfire threat. ","firebreakCategory":"The density of the structures in the area surrounding your property is high and is not a factor in the wildfire threat to this property. ","trackingId":"c71024af17b85203ab79dc94bdb81756"}