Error loading JSON nodes

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
tgoldsby
Posts: 3
Joined: Mon Mar 14, 2022 10:43 pm

Error loading JSON nodes

Post by tgoldsby »

PROBLEM is at the end of this post.

JSON response from web service is in variable WsOut (length 1048576a, varying):
{
"messages": [
{
"messageType": "MESSAGE_TYPE_INFO",
"messageCode": "0",
"messageText": "Service Completed Successfully"
}
],
"source": "CARFAX",
"transactionId": "YjDDuVlwnVZTYN9Breb3AgAAAJI",
"results": [
{
"vin": "JTHBE96S570019305",
"referenceNumber": "Thea testing",
"year": "2007",
"make": "LEXUS",
"model": "GS 350",
"readings": [
{
"mileage": "212652",
"recordedDate": 1489219200000
},
{
"mileage": "167541",
"recordedDate": 1426230000000
},
{
"mileage": "123099",
"recordedDate": 1367564400000
},
{
"mileage": "21",
"recordedDate": 1179385200000
}
],
"systemResult": {
"autoCheckReport": null,
"carfaxAMC": {
"odometerProblems": null,
"odometerBrandedTitle": null,
"lastOwner": {
"averageAnnualMileage": "21643",
"recentAverageMileage": "22586",
"californiaRecentAnnualMileage": "22586",
"modeledAnnualMileage": "11263",
"firstOdometerMileage": "21",
"firstOdometerDate": 1179385200000,
"lastOdometerMileage": "212652",
"lastOdometerDate": 1489219200000
},
"estimatedCurrentMileage": "246561"
},
"carfaxDML": {
"description": {
"year": "2007",
"make": "LEXUS",
"model": "GS 350"
},
"ownershipInfo": {
"lastOwnerAcquisitionDate": 1179385200000,
"lastOwnerTitlingState": "CA",
"titleNumber": null,
"lastOwnerCity": "Downey",
"lastOwnerState": "CA",
"lastOwnerZipCode": "90241",
"lastOwnerLastOdometerMileage": "212652"
},
"forSale": false,
"forSaleDate": null
},
"carfaxODC": {
"lastOwnerOdometerReadingCount": 4,
"lastOwnerOdometerReadings": [
{
"mileage": "21",
"date": 1179385200000,
"government": true
},
{
"mileage": "123099",
"date": 1367564400000,
"government": true
},
{
"mileage": "167541",
"date": 1426230000000,
"government": true
},
{
"mileage": "212652",
"date": 1489219200000,
"government": true
}
],
"modeledAnnualMileage": "11263",
"odometerProblems": null
},
"carfaxTBC": null
},
"messages": [
{
"messageType": "MESSAGE_TYPE_INFO",
"messageCode": "0",
"messageText": "Service Completed Successfully"
}
]
}
]
}


Node definitions:
D Response s like(yajl_val)
D node s like(yajl_val)
D val s like(yajl_val)
D messages s like(yajl_val)
D results s like(yajl_val)
D readings s like(yajl_val)
D systemResult s like(yajl_val)

Tree successfully loads into ‘Response’
Response = yajl_string_load_tree(ResponseJSON: YAJLerrMsg );

Nodes ‘source’ and ‘transactionID’ are successfully found
node = YAJL_object_find(Response: 'source');
SOURCE = YAJL_get_string(node);

node = YAJL_object_find(Response: 'transactionId');
TRANSID = YAJL_get_string(node);

Node ‘messages’ is successfully found.
messages = YAJL_object_find(Response: 'messages');
ExSr $Parse_messages;
This node is a list. I’m following Scott’s example of processing a list from his “Working with JSON in RPG” presentation. The sub-nodes within the ‘messages’ list are successfully found and the loop count is accurate.

Node ‘results’ is successfully found. This node is a list.
results = YAJL_object_find(Response: 'results');
ExSr $Parse_results;

// --------------------------------------------------------------------------------------------------------------

BegSR $Parse_results;

Reset ResultsLoop;
Reset ResultsCount;

DoW YAJL_ARRAY_LOOP( results: ResultsLoop: node );
ResultsCount = ResultsLoop;

Nodes ‘year’ and ‘make’ are successfully found
val = YAJL_object_find(node: 'year');
YEAR = YAJL_get_string(val);

val = YAJL_object_find(node: 'make');
MAKE = YAJL_get_string(val);

Node ‘readings’ is successfully found. The list processing successfully finds the sub-nodes with each item in the list and correctly counts the number of items in the list.
readings = YAJL_object_find(node: 'readings');
ExSr $Parse_readings;

HERE IS THE PROBLEM: trying to load node ‘systemResult’ blows up with error message ID RNQ0202 “The call to YAJL_OBJEC ended in error”.
systemResult = YAJL_object_find(node: 'systemResult');
In the job log, this error is immediately preceded by “Pointer not set for location referenced” and “Function check. MCH3601 unmonitored by YAJL at statement 0000000001, instruction X'0000'.” Let me know whether you want me to upload the dump from this (913 pages).
tgoldsby
Posts: 3
Joined: Mon Mar 14, 2022 10:43 pm

Re: Error loading JSON nodes

Post by tgoldsby »

Additional info: this morning as an experiment I rearranged the steps within loop YAJL_ARRAY_LOOP( results: ResultsLoop: node ). I moved systemResult = YAJL_object_find(node: 'systemResult') to be the first step: systemResult loaded and parsed correctly, including its sub-nodes. However, the next step in the loop, val = YAJL_object_find(node: 'year'), blew up with the same "Pointer not set" error.

I think the problem may be that I am using "node" in loops within this "results" loop. I will make each loop have a unique third parameter then report back.
tgoldsby
Posts: 3
Joined: Mon Mar 14, 2022 10:43 pm

Re: Error loading JSON nodes

Post by tgoldsby »

Yep, that was it, PROBLEM SOLVED. Loops within loops need to use unique variables as the 3rd parameter of YAJL_ARRAY_LOOP. Obvious now that I see it.
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: Error loading JSON nodes

Post by jonboy49 »

To avoid issues like this I tend to create a specifically named node whenever it is needed in a loop or will be used to locate sub nodes. You did it earlier on in your code but then started using node for multiple purposes. I find it makes debugging far easier too.
Post Reply