I'm new to using YAJL so could use some guidance on handling nested objects/arrays.
I've attached my JSON response which I am loading from a *STMF.
I'm able to locate the node for the tracking object and shipment array.
I was hoping to get the node for the "package" array using the shipment node (shpNode) but that is returning nulls.
So, I'm using the node for the shipment array (shpNode) to try and drill down to ultimately get to the package array and then the delivery date array.
This is where I'm getting a little lost.
When looping through the shipment array looking for my ojbects, I can ultimately get "key" to resolve to a value of "package".
I tried to use yajl_find_object to get to the deliveryDate array but I know that is wrong and I'm pretty turned around at this point.
If you can provide some guidance on what my next step in the code should be I'd appreciate it.
Code: Select all
dcl-s trkNode like(docNode);
dcl-s shpNode like(docNode);
dcl-s delNode like(docNode);
dcl-s node like(yajl_val);
dcl-s list like(yajl_val);
dcl-s val like(yajl_val);
dcl-s valnum zoned(5:0) Inz;
dcl-s valStr like(resultStr);
dcl-s errMsg varchar(500);
dcl-s i int(10) inz;
dcl-s j int(10) inz;
D resultStmf s 5000a varying
// parse JSON
docNode = yajl_stmf_load_tree(resultStmf
:Errmsg);
If errMsg = ' ';
trkNode = yajl_object_find (docNode : 'trackResponse');
shpNode = yajl_object_find (trkNode : 'shipment');
//pkgNode = yajl_object_find (shpNode : 'package); //returns nulls
i = 0;
Dow yajl_array_loop(shpNode : i : node);
j = 0;
Dow yajl_object_loop(node : j : key : val);
If key = 'package';
delNode = yajl_Object_find (node : 'deliveryDate');
Endif;
Enddo;
Enddo;
Endif;
Code: Select all
{
"trackResponse": {
"shipment": [
{
"inquiryNumber": "1Z3794540215045372",
"package": [
{
"trackingNumber": "1Z3794540215045372",
"deliveryDate": [
{
"type": "DEL",
"date": "20221010"
}
],
"deliveryTime": {
"type": "DEL",
"endTime": "150653"
},
"activity": [
{
"location": {
"address": {
"city": "TRENTON",
"stateProvince": "NJ",
"countryCode": "US",
"country": "US"
},
"slic": "0863"
},
"status": {
"type": "D",
"description": "DELIVERED ",
"code": "FS",
"statusCode": "011"
},
"date": "20221010",
"time": "150653"
},
{
"location": {
"address": {
"city": "Hamilton",
"stateProvince": "NJ",
"countryCode": "US",
"country": "US"
},
"slic": "0863"
},
"status": {
"type": "I",
"description": "Out For Delivery Today",
"code": "OT",
"statusCode": "021"
},
"date": "20221010",
"time": "085730"
},
{
"location": {
"address": {
"city": "Hamilton",
"stateProvince": "NJ",
"countryCode": "US",
"country": "US"
},
"slic": "0860"
},
"status": {
"type": "I",
"description": "Processing at UPS Facility",
"code": "DS",
"statusCode": "087"
},
"date": "20221010",
"time": "060250"
},
{
"location": {
"address": {
"city": "Hamilton",
"stateProvince": "NJ",
"countryCode": "US",
"country": "US"
},
"slic": "0799"
},
"status": {
"type": "I",
"description": "Arrived at Facility",
"code": "AR",
"statusCode": "005"
},
"date": "20221009",
"time": "162200"
},
{
"location": {
"address": {
"city": "Parsippany",
"stateProvince": "NJ",
"countryCode": "US",
"country": "US"
},
"slic": "0799"
},
"status": {
"type": "I",
"description": "Departed from Facility",
"code": "DP",
"statusCode": "005"
},
"date": "20221009",
"time": "145200"
},
{
"location": {
"address": {
"city": "Parsippany",
"stateProvince": "NJ",
"countryCode": "US",
"country": "US"
},
"slic": "1949"
},
"status": {
"type": "I",
"description": "Arrived at Facility",
"code": "AR",
"statusCode": "005"
},
"date": "20221008",
"time": "131300"
},
{
"location": {
"address": {
"city": "Philadelphia",
"stateProvince": "PA",
"countryCode": "US",
"country": "US"
},
"slic": "1949"
},
"status": {
"type": "I",
"description": "Departed from Facility",
"code": "DP",
"statusCode": "005"
},
"date": "20221008",
"time": "094800"
},
{
"location": {
"address": {
"city": "Philadelphia",
"stateProvince": "PA",
"countryCode": "US",
"country": "US"
},
"slic": "3269"
},
"status": {
"type": "I",
"description": "Arrived at Facility",
"code": "AR",
"statusCode": "005"
},
"date": "20221007",
"time": "211700"
},
{
"location": {
"address": {
"city": "Orlando",
"stateProvince": "FL",
"countryCode": "US",
"country": "US"
},
"slic": "3269"
},
"status": {
"type": "I",
"description": "Departed from Facility",
"code": "DP",
"statusCode": "005"
},
"date": "20221007",
"time": "035100"
},
{
"location": {
"address": {
"city": "Orlando",
"stateProvince": "FL",
"countryCode": "US",
"country": "US"
},
"slic": "3269"
},
"status": {
"type": "I",
"description": "Arrived at Facility",
"code": "AR",
"statusCode": "005"
},
"date": "20221007",
"time": "030500"
},
{
"location": {
"address": {
"city": "Orlando",
"stateProvince": "FL",
"countryCode": "US",
"country": "US"
},
"slic": "3269"
},
"status": {
"type": "I",
"description": "Departed from Facility",
"code": "DP",
"statusCode": "005"
},
"date": "20221007",
"time": "030300"
},
{
"location": {
"address": {
"city": "Orlando",
"stateProvince": "FL",
"countryCode": "US",
"country": "US"
},
"slic": "3289"
},
"status": {
"type": "I",
"description": "Arrived at Facility",
"code": "AR",
"statusCode": "005"
},
"date": "20221006",
"time": "222000"
},
{
"location": {
"address": {
"city": "Orlando",
"stateProvince": "FL",
"countryCode": "US",
"country": "US"
},
"slic": "3289"
},
"status": {
"type": "I",
"description": "Departed from Facility",
"code": "DP",
"statusCode": "005"
},
"date": "20221006",
"time": "221600"
},
{
"location": {
"address": {
"city": "Deerfield Beach",
"stateProvince": "FL",
"countryCode": "US",
"country": "US"
},
"slic": "3326"
},
"status": {
"type": "I",
"description": "Origin Scan",
"code": "OR",
"statusCode": "005"
},
"date": "20221005",
"time": "202511"
},
{
"location": {
"address": {
"countryCode": "US",
"country": "US"
}
},
"status": {
"type": "M",
"description": "Shipper created a label, UPS has not received the package yet. ",
"code": "MP",
"statusCode": "003"
},
"date": "20221005",
"time": "141503"
}
],
"packageCount": 1
}
],
"userRelation": [
"SHIPPER"
]
}
]
}
}